Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Part 2: Object-oriented programing with C++

Part 2: Object-oriented programing with C++

This part of the book provides you with basic tools of object-oriented programming with C++. Object-oriented programming is first and foremost about using functions because each operation on an object should be implemented as a function call. C++ functions are complex, and Chapter 7, "Programming with C++ Functions," tells you all you should know about the syntax of C++ functions. Passing parameters in C++ has a reputation for difficulty, and I hope that this chapter does a good job helping you to master this essential C++ skill.

Chapter 8, "Object-Oriented Programming with Functions," continues the discussion of C++ functions by explaining how to use functions. It introduces the criteria of cohesion, coupling, encapsulation, and information hiding and discusses the principle of readability and independence of program functions. It shows that most of the benefits of object-oriented programming can be achieved without using C++ objects, by designing access functions that the client code calls (instead of accessing structure fields directly). It also demonstrates the limitations of object-oriented programming with functions and lists the goals that the use of C++ classes has to achieve. This chapter is very important for developing the right intuition about object-oriented programming.

Chapter 9,"C++ Class as a Unit of Modularization," introduces the jewel of C++ programming: C++ classes. It describes the syntax of C++ class definition and discusses data members, member functions, control of access to class members, object initialization and destruction, returning objects from functions,and other technical details of using objects. The chapter contains a lot of complex details—there is no way around this: C++ classes are sophisticated. Make sure that these technical details do not hide from you the main goal of using classes: suppressing minute details when the maintenance programmer needs to understand the general meaning of processing and data flows between the functions.

Chapter 10, "Operator Functions: Another Good Idea," describes operator functions, a nice part of C++ syntax. Operator functions are introduced into the language to support the philosophical concept that a program should be able to do to class objects everything that it can do to numerical variables—add, subtract, and so on. This concept is not very important from the point of view of software engineering principles, but it gives a nice syntactic touch to C++ sourcecode.

Chapter 11, "Constructors and Destructors: Potential Trouble," discusses the dangers of naïve use of C++ constructors and destructors and explains howto recognize these dangers. It offers several techniques for avoiding memory corruption and memory leaks. It is a very important chapter—an inexperienced C++ programmer can do a lot of damage by handling object initialization incorrectly.


You are currently reading a PREVIEW of this book.


Get instant access to over $1 million worth of books and videos.


Start a Free Trial

  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint