?
Solved

9. What is a composition?

Posted on 2015-01-23
1
Medium Priority
?
76 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

719 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