-
Notifications
You must be signed in to change notification settings - Fork 19
/
designpatterns.txt
80 lines (55 loc) · 2.88 KB
/
designpatterns.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
*Design Patterns*narrative
Structural patterns
Help manage how classes organize
Command
Allows you to encapsulate Requests as an object letting you parametrize clients with different requests. It is used in UI panels (actions).
Interpreter
Defines the grammar of a language and is able to interpret it. I.E the southest city given a set of them.
Iterator
Mechanisk to access aggregated elements without exposing its representation (next/hasnext/remove).
Mediator
It is an object that encapsulates how a set of objects interact. Promotes loos coupling by keeping objects from referencing each other.
Flyweight
It's a factory class, that allows creating multiple objects, buffering the ones you already created to avoid having to create them again (i.e.in a map).
Proxy
Provides a place holder to control an access an object. This is useful if you don't want to modify the object itself. For instance, a very time consuming method can be run a thread of the proxy.
Behavioural patterns
Help manage what classes actually do
Chain of responsability
Each element of the chain does a small task of work and delegate to the next one.
Adapter
Convert a given interface to another interface.
Bridge
Separates abstraction from implementation so that they can vary independently.
Composite
Different objects that have to be dealt with.
Decorator
Attach additional responsabilities to an object dynamically.
Facade
Higher level interface that groups a set of interfaces to facilitat client code's work.
Builder
Separate construction of complex object from its representation.
Factory
Interface for creating an object, let subclasses decide which one.
Prototype
When creating new instances is expensive, you can extend clonable and use a single instance you can clone.
Singleton
A class that has a single instance.
Creational Patterns
They facilitate creating other classes
Abstract factory
Creates families or related objects without specifying concrete classes.
Simple Factory
Delegating instantiation of objects to a specific class, useful when the creation of the object is complex (strategies/states/...).
Null Object
Specific dummy implementation of an interface, provides no behaviour, used to avoid having to check for actual null objects.
Curiously recurring generic pattern
A builder super class can hold a generic type, bounded to its type. Subclasses can pass its type so the builder methods within the super class return the correct subtype.
*Class Builder<T extends Builder>
T withFoo(foo)
return (T) this;
Class SubBuilder extends Builder<SubBuilder>*
Concurrency Patterns
Facilitate dealing with threads
Double-checked locking
Reduces lock contention by testing the locking criterion withouth aquiring the lock, then if the testing is successful it is tested again after acquiring the lock.