FAQ 5.05 Why are classes important?

graphics/new_icon.gif

Classes are the fundamental packaging unit of OO technology.

Classes are a way to localize all the state (data) and services (typically member functions) associated with a cohesive concept. The main idea is to organize things so that when changes to the concept or abstraction occur (as is inevitable), it will be possible to go to one place to make the necessary modifications. We have seen examples in the procedural world where a simple change required modifying dozens of source code files. This shouldn't happen with a proper OO class definition, but we recall one C++ project where a simple change required modifying 46 different files. Obviously, the people responsible for this failure didn't "get it"; they may have been using C++, but they weren't using it properly. It's easy for beginners, no matter how much experience they have, to fall into this trap.

Here is the skeletal syntax for a typical class definition:

 class ClassName { public:                                                      <-- 1 protected:                                                      <-- 2 private:                                                      <-- 3 }; 

(1) Public member functions declared here

(2) Protected data and member functions declared here

(3) Private data and member functions declared here

Here is the UML representation of a class.

graphics/05fig01.gif



C++ FAQs
C Programming FAQs: Frequently Asked Questions
ISBN: 0201845199
EAN: 2147483647
Year: 2005
Pages: 566
Authors: Steve Summit

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