下载 > 资源分类 >  开发技术 >  C > Object-oriented programming with C language

Object-oriented programming with C language

2015-12-05 上传大小:1.2MB
<<Object-oriented programming with C language>>

No programming technique solves all problems.
No programming language produces only correct results.
No programmer should start each projec
t from scratch.
Object-oriented programming is the current cure-all — although it has been
around for much more then ten years. At the core, there is little more to it then
finally applying the good programming principles which we have been taught for
more then twenty years. C++ (Eiffel, Oberon-2, Smalltalk ... take your pick) is the
New Language because it is object-oriented — although you need not use it that
way if you do not want to (or know how to), and it turns out that you can do just as
well with plain ANSI-C. Only object-orientation permits code reuse between projects — although the idea of subroutines is as old as computers and good programmers always carried their toolkits and libraries with them.
This book is not going to praise object-oriented programming or condemn the
Old Way. We are simply going to use ANSI-C to discover how object-oriented programming is done, what its techniques are, why they help us solve bigger problems, and how we harness generality and program to catch mistakes earlier. Along
the way we encounter all the jargon — classes, inheritance, instances, linkage,
methods, objects, polymorphisms, and more — but we take it out of the realm of
magic and see how it translates into the things we have known and done all along.
I had fun discovering that ANSI-C is a full-scale object-oriented language. To
share this fun you need to be reasonably fluent in ANSI-C to begin with — feeling
comfortable with structures, pointers, prototypes, and function pointers is a must.
Working through the book you will encounter all the newspeak — according to
Orwell and Webster a language ‘‘designed to diminish the range of thought’’ — and
I will try to demonstrate how it merely combines all the good programming principles that you always wanted to employ into a coherent approach. As a result, you
may well become a more proficient ANSI-C programmer.
The first six chapters develop the foundations of object-oriented programming
with ANSI-C. We start with a careful information hiding technique for abstract data
types, add generic functions based on dynamic linkage and inherit code by judicious
lengthening of structures. Finally, we put it all together in a class hierarchy that
makes code much easier to maintain.
Programming takes discipline. Good programming takes a lot of discipline, a
large number of principles, and standard, defensive ways of doing things right. Programmers use tools. Good programmers make tools to dispose of routine tasks
once and for all. Object-oriented programming with ANSI-C requires a fair amount
of immutable code — names may change but not the structures. Therefore, in
chapter seven we build a small preprocessor to create the boilerplate required. It
looks like yet another new object-oriented dialect language (yanoodl perhaps?) but
it should not be viewed as such — it gets the dull parts out of the way and lets us
concentrate on the creative aspects of problem solving with better techniques. ooc
(sorry) is pliable: we have made it, we understand it and can change it, and it
writes the ANSI-C code just like we would.
The following chapters refine our technology. In chapter eight we add dynamic
type checking to catch our mistakes earlier on. In chapter nine we arrange for
automatic initialization to prevent another class of bugs. Chapter ten introduces
delegates and shows how classes and callback functions cooperate to simplify, for
example, the constant chore of producing standard main programs. More chapters
are concerned with plugging memory leaks by using class methods, storing and
loading structured data with a coherent strategy, and disciplined error recovery
through a system of nested exception handlers.
Finally, in the last chapter we leave the confines of ANSI-C and implement the
obligatory mouse-operated calculator, first for curses and then for the X Window
System. This example neatly demonstrates how elegantly we can design and
implement using objects and classes, even if we have to cope with the idiosyncrasies of foreign libraries and class hierarchies.
Each chapter has a summary where I try to give the more cursory reader a rundown on the happenings in the chapter and their importance for future work. Most
chapters suggest some exercises; however, they are not spelled out formally,
because I firmly believe that one should experiment on one’s own. Because we are
building the techniques from scratch, I have refrained from making and using a
massive class library, even though some examples could have benefited from it. If
you want to understand object-oriented programming, it is more important to first
master the techniques and consider your options in code design; dependence on
somebody else’s library for your developments should come a bit later.
An important part of this book is the enclosed source floppy — it has a DOS file
system containing a single shell script to create all the sources arranged by chapter.
There is a ReadMe file — consult it before you say make. It is also quite instructive
to use a program like diff and trace the evolution of the root classes and ooc reports
through the later chapters.
The techniques described here grew out of my disenchantment with C++ when
I needed object-oriented techniques to implement an interactive programming
language and realized that I could not forge a portable implementation in C++. I
turned to what I knew, ANSI-C, and I was perfectly able to do what I had to. I have
shown this to a number of people in courses and workshops and others have used
the methods to get their jobs done. It would have stopped there as my footnote to
a fad, if Brian Kernighan and my publishers, Hans-Joachim Niclas and John Wait,
had not encouraged me to publish the notes (and in due course to reinvent it all
once more). My thanks go to them and to all those who helped with and suffered
through the evolution of this book. Last not least I thank my family — and no,
object-orientation will not replace sliced bread.
Hollage, October 1993
Axel-Tobias Schreiner
...展开收缩
综合评分:0(0位用户评分)
直接下载 开通VIP会员 免积分下载

评论共有0条

评论资源

您不能发表评论,可能是以下原因:

登录后才能评论

待评论资源
 

热门专辑

关闭
img

spring mvc+mybatis+mysql+maven+bootstrap 整合实现增删查改简单实例.zip

CSDN VIP年卡 4000万程序员的必选现在开通,立省522元
下载
img

Object-oriented programming with C language

会员到期时间: 剩余下载个数: 剩余C币:0 剩余积分:
VIP下载

积分不足!

资源所需积分 当前拥有积分
您可以选择
开通VIP年卡
4000万
程序员的必选
600万
绿色安全资源
现在开通
立省522元
或者
购买C币兑换积分 C币抽奖
img
资源所需积分 当前拥有积分 当前拥有C币
5 4 45
(仅够下载10个资源)
VIP年卡
全站1200个资源免积分下载
下载
img
资源所需积分 当前拥有积分 当前拥有C币
5 0 0
VIP年卡
全站1200个资源免积分下载
C币充值开通VIP年卡
img
资源所需积分 当前拥有积分 当前拥有C币
5 4 45
您的积分不足,将扣除 10 C币
VIP年卡
全站1200个资源免积分下载
下载
下载

兑换成功

你当前的下载分为234开始下载资源
你还不是VIP会员
开通VIP会员权限,免积分下载
立即开通

你下载资源过于频繁,请输入验证码

你下载资源过于频繁,请输入验证码

您因违反CSDN下载频道规则而被锁定帐户,如有疑问,请联络:webmaster@csdn.net!

举报

若举报审核通过,可奖励20下载分

  • 举报人:
  • 被举报人:
  • 举报的资源分:
  • *类型:
  • *详细原因: