Constructing Simple Hierarchies with Composition

Constructing Simple Hierarchies with Composition

For access to this article, please select a purchase option:

Buy chapter PDF
(plus tax if applicable)
Buy Knowledge Pack
10 chapters for £75.00
(plus taxes if applicable)

IET members benefit from discounts to all IET publications and free access to E&T Magazine. If you are an IET member, log in to your account and the discounts will automatically be applied.

Learn more about IET membership 

Recommend Title Publication to library

You must fill out fields marked with: *

Librarian details
Your details
Why are you recommending this title?
Select reason:
A Guide to MATLAB® Object-Oriented Programming — Recommend this title to your library

Thank you

Your recommendation has been sent to your librarian.

There is another common form of inheritance, very different from parent-child inheritance, called composition. Using an object in composition is easy. All you have to do is assign an object as the value for a private member variable. For example, if double represents a class, we could say that this.mSize is one element of the composition. This means that even simple classes use a composition of built-in types. Complex classes add structures and objects to the composition. Unlike parent-child inheritance where the parent's interface is public, the interface of every object in the composition remains private. In MATLAB, there is overlap between parent-child inheritance and composition. Parent-child inheritance is a special case of composition. The child is a primary object and the parent is a secondary object. This might seem backward but it is consistent with the way primary and secondary were defined. The parent is a secondary object because the parent object is stored as an element in the child's private structure.

Chapter Contents:

  • 15.1 Composition
  • 15.1.1 The cLineStyle Class
  • cLineStyle's private/ctor_ini
  • cLineStyle's fieldnames
  • cLineStyle's get
  • cLineStyle's set
  • cLineStyle's private/ctor_2
  • 15.1.2 Using a Primary cShape and a Secondary cLineStyle
  • Composition Changes to cShape's ctor_ini.m
  • Adding LineWeight to cShape's fieldnames.m
  • Composition Changes to cShape's get.m
  • Composition Changes to cShape's set.m
  • Composition Changes to cShape's draw.m
  • Composition Changes to cShape's Other Member Functions
  • 15.2 Test Drive
  • 15.3 Summary
  • 15.4 Independent Investigations

Inspec keywords: object-oriented programming

Other keywords: private member variable; child object; parent object; Matlab; this.mSize function; parent-child inheritance; simple hierarchy construction; parent-child composition

Subjects: Object-oriented programming

Preview this chapter:
Zoom in

Constructing Simple Hierarchies with Composition, Page 1 of 2

| /docserver/preview/fulltext/books/pc/sbpc001e/SBPC001E_ch15-1.gif /docserver/preview/fulltext/books/pc/sbpc001e/SBPC001E_ch15-2.gif

Related content

This is a required field
Please enter a valid email address