190 likes | 202 Views
Introduction to Design Patterns. Questions. What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared to the rest of the world? How different are patterns in APL?. What are design patterns?.
E N D
Questions • What is a design pattern? • Who needs design patterns? • How different are classes and objects in APL compared to the rest of the world? • How different are patterns in APL?
What are design patterns? • Design patterns are solution templates for frequently occurring problems. This term is widely applied to the design of Objects and their relations with each other.
Who needs design patterns? • The only classes in my first application using Object Oriented programming where static classes. If you are in the same boat why do we need Object Orientation at all.
How different are classes and objects in APL? • Type less nature of variables/objects – Type of variable is defined at the runtime.. • State full nature of workspace – workspace at every point in time has preexisting state. • Something else …
Effect of type-less nature on classes/objects • Strong typing of results helps resolving data type compatibility problems at a time of compilation. • Absence of strong typing gives flexibility for developers at implementation time, but may cause type compatibility issues at a runtime. • Properties/fields and method’s results of classes are not strongly typed. • As we will see it may be good or bad
Effect of state full workspace on classes • State of class is defined by static members (fields, properties) of class (State of object is defined by dynamic members) • State full nature of workspace may be described as the fact that at every point in time workspace is continuation of previous work rather then start from scratch. Static members are assigned at the time of class initialization. And may already change several times during test run before workspace will be saved. So application will start with static members which comes not from class definition but from intermediate state prior workspace saving.
Creational patterns • Singleton • Abstract Factory • Factory Method • Prototype • Builder
Structural Patterns • Adapter • Bridge • Composite • Decorator • Façade • Flyweight • Proxy
Behavioral patterns • Chain of Responsibility. • Command • Interpreter • Iterator • Mediator • Memento • Observer • State • Strategy • Template Method • Visitor
Singleton Definition: Singleton is a class of which only a single instance may exist at every given time. Features: • Provide alternative mechanism for object creation. • Prevent regular object creation.
Singleton Possible use: • Load Balancers • Configuration class • Access to the object pool • Iterators • …
Prototype Definition: Create an object by copying existing rather then using []NEW. Features: • Utilize cloning of objects as alternative way to create instance instead of regular object creation. • No need to prevent regular object creation.
Prototype Possible use: • Classes with time and resource consuming initialization process
Abstract Factory Definition: Creates a series of objects without specifying object class. Features: • Need for interface structure defined. • Need for multiple interface implementations
Abstract Factory Note: It is more relevant to the strongly typed world as strong typing puts limitations, which this pattern trying to resolve. Possible use: 1. Tools which operate/generate different classes with the same interface
Adapter Definition: Creates an interface representing another interface/class. Features: • Need for interface structure defined. • Need for multiple interface implementations
Adapter Definition: Creates an interface to represent another interface/class. Features: • Allows encapsulation of class behavior.
Proxy Definition: Creates an interface representing another interface/class. Features: • Need for interface structure defined. • Need for multiple interface implementations