Solved

9. What is a composition?

Posted on 2015-01-23
1
66 Views
Last Modified: 2015-01-25
What is a composition? (related to Object-oriented paradigm)
0
Comment
Question by:Nusrat Nuriyev
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now