Book Image

TypeScript Design Patterns

By : Vilic Vane
Book Image

TypeScript Design Patterns

By: Vilic Vane

Overview of this book

In programming, there are several problems that occur frequently. To solve these problems, there are various repeatable solutions that are known as design patterns. Design patterns are a great way to improve the efficiency of your programs and improve your productivity. This book is a collection of the most important patterns you need to improve your applications’ performance and your productivity. The journey starts by explaining the current challenges when designing and developing an application and how you can solve these challenges by applying the correct design pattern and best practices. Each pattern is accompanied with rich examples that demonstrate the power of patterns for a range of tasks, from building an application to code testing. We’ll introduce low-level programming concepts to help you write TypeScript code, as well as work with software architecture, best practices, and design aspects.
Table of Contents (15 chapters)
TypeScript Design Patterns
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface

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...