C++ Objects

While reading through chapter one of http://www.planetpdf.com/codecuts/pdfs/eckel/TIC2Vone.zip I learned what classes, objects, and member objects are. I also learned what inheritance and polymorphism are.


To solidify my learning of this chapter, I’ll summarize each of these concepts, then go back through the book and confirm what I wrote.


Classes:
Classes are what are known as “types” of objects. A class is simply a group of objects which are related in some way, and programmers can define their own classes, as well as re-use pre-existing classes from other code.


Objects:
Objects are what makes up a class. Similar objects are grouped together into classes, and usually perform very similar functions and share similar behaviors. Objects can be cloned with each clone performing independently of the other clones.


Member Objects:
Member objects are objects from different classes all piled together to construct a new type of class. This concept is known as composition. Composition should be looked to use when creating new classes over inheritance, because it will result in simpler and cleaner designs.


Inheritance:
Inheritance is the act of taking a class and cloning it, then making necessary modifications to it.


Polymorphism:
Polymorphism is the idea of creating code to be executed without being dependent on specific data types. This is useful when you want to treat a variety of objects with the same function call. Although, this means that what code specifically executes won’t be determined until runtime. This is where late binding comes into play. Late binding allows the object’s properties to determine which actions to take during runtime when a particular function or command is called or sent. This will allow a single call to something like “draw” to be applicable to a wide range of objects of class “shape” without having to worry about which type of shape is being operated upon.


I plan to tomorrow take a look at chapter 2, which covers the implementation of objects in code.

TwitterRedditFacebookShare

Leave a Reply

Your email address will not be published. Required fields are marked *