Working on an assignment and I\'m having a little trouble remembering these conc
ID: 3635468 • Letter: W
Question
Working on an assignment and I'm having a little trouble remembering these concepts from previous classes, just hoping to get help on what they mean.
What would "abstraction by composition of two self-written classes" mean?
Polymorphism, and what would be considered a polymorphic container (can be self-written or come from a C++ library)
Using aggregate operations on the polymorphic container, what would this involve? I guess the definition of aggregate operations is needed.
Keep in mind these might not be text book concepts, I have searched quite a bit and found nothing concrete, I think they are more of an instructor specific way of describing things. I could be wrong, but I'm weak in CS conceptual topics anyway. Anyone with good knowledge of the field to explain these would be much appreciated. Thanks!
Explanation / Answer
So, abstraction by composition of two self-written classes basically means – to combine those two classes by composition in probably another class. Look at simple example: PC has CPU and HD components, so PC class can be composed of a CPU and HD classes. To compose a class from existing classes, u should declare object of those classes as a member of the new class. You CPU class then will look like this: class CPU // composed class { HD seagate; // an object 'seagate' of HD class CPU intel; // an object 'intel' of CPU class public: CPU(); ~CPU(); }; Usually classes that are used to build a composed class r called subclasses and their objects usually referred to as embedded object or subobjects. Abstraction here achieved by using the composition. Abstraction is a general term which basically means to generalize. It is one of the tree main concepts of object-oriented programming. Here in this particular example u generalize PC by saying “PC has a HD and CPU”, but u r not describing the design of HD and CPU while describing PC. Then, Polymorphism is another main concept of OOP. The idea of polymorphism is to design an interface(functions), that can be used on different objects which are related. That usually reduces the complexity of the particular design. Virtual functions and abstract base classes are fundamental tools in polymorphism. Polymorphic container is usually the contained which has them. The container is an object that stores other objects. C++ provides some basic templates in STL(Standart template library) Aggregate operation means that the operation acts on the structure as a whole whereas normal operations deal with individual members. Basically In this example aggregate operation would have been the addition of two objects of PC class, for instance. Usually, the operator overloading is used for that purpose. Aggregate operation on polymorphic containers involves that u r basically doing some operations with several containers, u might define a function for that or define an overloaded operation. For example – u are using two vector containers and u r pushing two strings into them, then u can define ‘+’ operator which is working with your vector containers to concatenate two strings. Hope this helps. If u need to go deep with OOP, u might refer to some literature for better understanding. Personally, I recommend u to look for "Object-Oriented Programming: Using C++ for Engineering and Technology", Goran Svenk. I found the explanation and examples there really good
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.