-
Book Overview & Buying
-
Table Of Contents
TypeScript Design Patterns
By :
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.
The participants of Composite Pattern implementation include: