19
Introduction to Design Patterns

Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared

Embed Size (px)

Citation preview

Page 1: Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared

Introduction to Design Patterns

Page 2: Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared

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?

Page 3: Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared

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.

Page 4: Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared

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.

Page 5: Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared

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 …

Page 6: Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared

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

Page 7: Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared

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.

Page 8: Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared

Creational patterns

• Singleton

• Abstract Factory

• Factory Method

• Prototype

• Builder

Page 9: Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared

Structural Patterns

• Adapter

• Bridge

• Composite

• Decorator

• Façade

• Flyweight

• Proxy

Page 10: Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared

Behavioral patterns

• Chain of Responsibility. • Command• Interpreter• Iterator• Mediator• Memento• Observer• State• Strategy• Template Method• Visitor

Page 11: Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared

Singleton

Definition:

Singleton is a class of which only a single instance may exist at every given time.

Features:

1. Provide alternative mechanism for object creation.

2. Prevent regular object creation.

Page 12: Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared

Singleton

Possible use:

1. Load Balancers

2. Configuration class

3. Access to the object pool

4. Iterators

5. …

Page 13: Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared

Prototype

Definition:Create an object by copying existing rather

then using []NEW.Features:1. Utilize cloning of objects as alternative

way to create instance instead of regular object creation.

2. No need to prevent regular object creation.

Page 14: Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared

Prototype

Possible use:

1. Classes with time and resource consuming initialization process

Page 15: Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared

Abstract Factory

Definition:

Creates a series of objects without specifying object class.

Features:

1. Need for interface structure defined.

2. Need for multiple interface implementations

Page 16: Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared

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

Page 17: Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared

Adapter

Definition:

Creates an interface representing another interface/class.

Features:

1. Need for interface structure defined.

2. Need for multiple interface implementations

Page 18: Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared

Adapter

Definition:

Creates an interface to represent another interface/class.

Features:

1. Allows encapsulation of class behavior.

Page 19: Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared

Proxy

Definition:

Creates an interface representing another interface/class.

Features:

1. Need for interface structure defined.

2. Need for multiple interface implementations