Solo disponible en BuenasTareas
  • Páginas : 2 (482 palabras )
  • Descarga(s) : 0
  • Publicado : 20 de diciembre de 2011
Leer documento completo
Vista previa del texto

OOP Concepts by Example
by Randy Charles Morin Of late, I have been writing very narrow focused articles that explain how to accomplish this or that task. Many of you have changedyour questions from the narrow focus of how-to questions to broader theorectical questions. One question I got lately that intrigue me was to explain the concepts of OOPs showing C++ examples. Let'sstart by laying down some ground work. I assume that you are familar with the following OOP concepts; classes, objects, attributes, methods, types. If not, then this article might not be in your realm.I'd suggest starting with the basic concepts of C++ before you attempt to understand the more indepth concepts that I'll be discussing in this article. When we speak of OOP concepts, the conversationusually revolves around encapsulation, inheritance and polymorphism. This is what I will attempt to describe in this article.

Let us start by defining inheritnace. A very good websitefor finding computer science definitions is The definitions in this article are stolen from that website. Definition: Inheritance Inheritance is the concept that when a classof object is defined, any subclass that is defined can inherit the definitions of one or more general classes. This means for the programmer that an object in a subclass need not carry its owndefinition of data and methods that are generic to the class (or classes) of which it is a part. This not only speeds up program development; it also ensures an inherent validity to the defined subclassobject (what works and is consistent about the class will also work for the subclass). The simple example in C++ is having a class that inherits a data member from its parent class.
class A { public:integer d; }; class B : public A { public: };

The class B in the example does not have any direct data member does it? Yes, it does. It inherits the data member d from class A. When one class...
tracking img