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
Solved

9. What is a composition?

Posted on 2015-01-23
1
71 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

766 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