Solved

9. What is a composition?

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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

623 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