Solved

9. What is a composition?

Posted on 2015-01-23
1
74 Views
Last Modified: 2015-01-25
What is a composition? (related to Object-oriented paradigm)
0
Comment
Question by:Nusrat Nuriyev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 40567785
I hate to do that again, but yet I find myself linking to Wikipedia rathern than trying to cite them: 'http://en.wikipedia.org/wiki/Object_composition

The concept is to bundle functionality by bundling objects that handle certain tasks and provide a common interface to do that. To distinguish my explanation from thar article, let's choose a different vehicle, maybe a bike. So, bikes have pedals, handlebars, brakes, etc. - you could compose a bike like

class Bicycle {
  public Bike() {}

  void Accelerate() {
     pedals.PushHarder();
  }

  void SlowDown() {
    break.PullLever();
  }

 protected:

  Pedals pedals;
  Brake brake;
};

Open in new window


So, all the functionality that make a bike up are broken down to components that your cloass controls and interacts with. Nice composition, isn't it? ;o)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question