Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
TypeScript Design Patterns

You're reading from  TypeScript Design Patterns

Product type Book
Published in Aug 2016
Publisher Packt
ISBN-13 9781785280832
Pages 256 pages
Edition 1st Edition
Languages
Author (1):
Vilic Vane Vilic Vane
Profile icon Vilic Vane

Composite Pattern


Objects under the same class could vary from their properties or even specific subclasses, but a complex object can have more than just normal properties. Taking DOM elements, for example, all the elements are instances of class Node. These nodes form tree structures to represent different pages, but every node in these trees is complete and uniform compared to the node at the root:

<html> 
  <head> 
    <title>TypeScript</title> 
  </head> 
  <body> 
    <h1>TypeScript</h1> 
    <img /> 
  </body> 
</html> 

The preceding HTML represents a DOM structure like this:

All of the preceding objects are instances of Node, they implement the interface of a component in Composite Pattern. Some of these nodes like HTML elements (except for HTMLImageElement) in this example have child nodes (components) while others don't.

Participants

The participants of Composite Pattern...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}