Introduction

 < Day Day Up > 



This chapter deals exclusively with the C++ class construct. Here you will learn about data encapsulation, horizontal member access, special member functions, initializer lists, member function overloading, and data member accessor and mutator functions. I will also introduce you to the Unified Modeling Language (UML) class diagram. All the material presented here is intended to give you a solid foundation for further study of C++ in the context of good object-oriented design.

You caught a glimpse of data encapsulation in action in chapter 10. There, structure and class data members were declared private to prevent unauthorized access. The material in this chapter continues that discussion and shows you how to control the horizontal access granted to a class’s data and function members using the access specifiers public, and private. The protected access specifier is covered in detail in chapter 13.

Something you did not see in the previous chapter were the special member functions called constructors and destructors. Constructors are used to initialize class objects to some known state. There should be no surprises regarding the state of instance data members when an object is created. Destructors are used to free any resources allocated for an object’s use during its lifetime. An initializer list is an extremely important part of a class constructor because it is the only place where class constants can be initialized. You will also need to know about initializer lists when you get to chapter 13.

Just as regular functions can be overloaded, so too can class member functions including constructors. You will learn several good reasons for doing so. You will also learn how to write class accessor and mutator functions to access and manipulate class data members.

The Unified Modeling Language is considered the standard for object-oriented software design. In this chapter I will introduce you to the UML class diagram. You will find it helpful to express your design ideas in pictures, especially when working with large numbers of classes. A full treatment of the UML is beyond the scope of this book, but if you are interested in learning more I suggest starting with one of the UML references listed at the end of chapter.



 < Day Day Up > 



C++ for Artists. The Art, Philosophy, and Science of Object-Oriented Programming
C++ For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504028
EAN: 2147483647
Year: 2003
Pages: 340
Authors: Rick Miller

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net