tailieunhanh - Lecture Software design and architecture – Chapter 30

Lecture Software design and architecture – Chapter 30: Design patterns. In this chapter, the following content will be discussed: Structural design patterns, façade pattern, creational design patterns, singleton pattern, builder pattern, singleton, singleton objects, the singleton solution. | SOFTWARE DESIGN AND ARCHITECTURE LECTURE 30 Review Structural Design Patterns Façade Pattern Outline Creational Design Patterns Singleton Pattern Builder Pattern Creational Design Patterns Creational Concern the process of object creation. Creational class patterns: defer some part of object creation to subclasses Creational object patterns: defer it to another object. Singleton Singleton objects Some classes have conceptually one instance Many printers, but only one print spooler One file system One window manager only create one object and reuse it Encapsulate the code that manages the reuse The Singleton solution Class is responsible for tracking its sole instance Provide static method/field to allow access to the only instance of the class Benefit: Reuse implies better performance Class encapsulates code to ensure reuse of the object; no need to burden client Singleton pattern 8 Builder Builder Intent: Separate the construction of a complex object from its representation so that the same construction process can create different representations. Builder Participants (Example) Builder (VehicleBuilder) specifies an abstract interface for creating parts of a Product object ConcreteBuilder (MotorCycleBuilder, CarBuilder, ScooterBuilder) constructs and assembles parts of the product by implementing the Builder interface defines and keeps track of the representation it creates provides an interface for retrieving the product Participants (Example) Director (Shop) constructs an object using the Builder interface Product (Vehicle) represents the complex object under construction. ConcreteBuilder builds the products internal representation and defines the process by which its assembled includes classes that define the constituent parts, including interfaces for assembling the parts into the final result Summary Creational Design Patterns Singleton Pattern Builder Pattern | SOFTWARE DESIGN AND ARCHITECTURE LECTURE 30 Review Structural Design Patterns Façade Pattern Outline Creational Design Patterns Singleton Pattern Builder Pattern Creational Design Patterns Creational Concern the process of object creation. Creational class patterns: defer some part of object creation to subclasses Creational object patterns: defer it to another object. Singleton Singleton objects Some classes have conceptually one instance Many printers, but only one print spooler One file system One window manager only create one object and reuse it Encapsulate the code that manages the reuse The Singleton solution Class is responsible for tracking its sole instance Provide static method/field to allow access to the only instance of the class Benefit: Reuse implies better performance Class encapsulates code to ensure reuse of the object; no need to burden client Singleton pattern 8 Builder Builder Intent: Separate the construction of a complex object from its representation so that .