java implementation of some design patterns testing with Spock Framework
adding State
- Allow the object for changing its behavior without changing its class.
adding Composite
- Compose objects into tree structure to represent part-whole hierarchies. Composite lets client treat individual objects and compositions of objects uniformly.
adding Template Method
- This pattern lets subclasses redefine certain steps of an algorithm without changing the algorithm’s structure.
adding Bridge
- This pattern is used to decouple an abstraction from its implementation so that the two can vary independently.
adding Proxy
- Allows us to create an intermediary that acts as an interface to another resource. We should use this pattern:
- when we want a simplified version of a complex or heavy object (Virtual Proxy)
- when the original object is present in different address space, and we want to represent it locally (Remote Proxy)
- when we want to add a layer of security to the original underlying object to provide controlled access based on access rights of the client (Protection Proxy)
adding Facade
- Encapsulates a complex subsystem behind a simple interface.
adding Adapter
- This pattern converts the interface of a class into another interface clients expect.
adding Command
- This pattern encapsulates a request as an object, thereby letting us parameterize other objects with different requests.
adding Decorator
- This pattern lets you attach new behaviors to objects by placing these objects inside special wrapper objects that contain the behaviors.
adding Observer
- Observable maintains a list of its dependents objects, called observers, and notifies them of any state changes.
adding Strategy
- Strategy Pattern defines a set of encapsulated algorithms that can be swapped to carry out a specific behaviour.
adding Abstract Factory
- Abstract Factory provides an interface for creating families of related or dependent objects without specifying their concrete classes.
adding Factory Method
- Factory Method pattern solving the problem of creating objects without having to specify the exact class of the object that will be created.
adding Fluent Builder
- Fluent Builder solving the problem of object constructor complexity
- Class Car has builder written manually
- Class CarWithLombok using Lombok to generate builder automatically
adding Singleton implementations
- Singleton lets you ensure that a class has only one instance.
- SimpleSingleton implementation is creating an instance during starting application
- NoInstanceBeforeFirstUseSingleton implementation creates an instance after first call getInstance() method
- ThreadSafeSingleton implementation is synchronizing method getInstance() for multithreading application
- BestSingleton implementation is synchronizing block of code only for first creating instance