week 8 Flashcards
Structural design pattern
focuses on simplifying the design of complex systems by identifying relationships between classes and objects. These patterns primarily deal with how classes and objects are composed to form larger structures, making it easier to manage and modify them.
behavioural pattern
They focus on the interaction between objects and the responsibility of objects.
creational
deal with object creation mechanisms, trying to create objects in a manner suitable to the situation.
Singleton
Singleton Pattern is a creational design pattern that lets you ensure
that a class has only one instance, while providing a global access point
to this instance
used often in logging in when we only need one instance of logging in service or one data base
How to code singleton in Java
public class Singleton {
private static Singleton uniqueInstance;
private Singleton() {
}
public static Singleton getInstance() {
if (uniqueInstance == null) {
return new Singleton(); //
} else {
return uniqueInstance;
}
}
//other methods
}
Strategy is a …… pattern
behavioural pattern
One of the key benefits of using the strategy pattern is that it allows the client to choose the appropriate algorithm at runtime, promoting flexibility and easy extension.
read
read
The strategy pattern promotes the “Open/Closed” principle of object-oriented design, allowing the system to be easily extended with new algorithms without modifying existing code.
what does facade do
[structural]
The primary purpose of the Facade Pattern is to hide the complexities of a subsystem and provide a single, unified interface for the client.
Facade look at the week 8 slides and video for facade . too hard to explain via words
do this
It is hard to remove a specific wrapper from the wrappers stack.
It is hard to implement a decorator in such a way that its behaviour doesn’t depend on the
order in the decorators stack.
eg in a file system you have a certain order
creating file
then wrapping in a file input stream
then wrapping it in a buffered input stream
HAS TO BE IN THIS ORDER
read