Structural Design Patterns Flashcards
Provide definition of Adapter pattern
Pattern that allows objects with
incompatible interfaces to collaborate
Provide definition of Bridge pattern
Bridge is a structural design pattern that lets you split a large class or a set of closely related classes into two separate
hierarchies—abstraction and implementation—which can be
developed independently of each other
What means Abstraction in Bridge pattern
Abstraction (also called interface) is a high-level control layer for some entity. This layer isn’t supposed to do any real work
on its own. It should delegate the work to the implementation layer (also called platform).
What means Impelementation in Bridge pattern
An interface or abstract class defining the low-level operational methods. This acts as a base for the concrete implementation
Provide definition od Composite pattern
Composite is a structural design pattern that lets you compose objects into tree structures and then work with these structures as if they were individual objects
What principle can be violated by Composite pattern and why?
Interface Segregation Principle can violated when Composite definies the methods Add, Remove. They will be empty in the leaf
class. However, the client will be able to treat all the elements equally, even when composing the tree
Provide definition for Decorator pattern
Structural design pattern that lets you attach
new behaviors to objects by placing these objects inside special wrapper objects that contain the behaviors
What means that inheritance is static
You can’t alter the behavior of an existing
object at runtime. You can only replace the whole object with another one that’s created from a different subclass
Which pattern manages the life
cycle of its service object on its own
Proxy
Provide definition for Facade pattern
Structural design pattern that provides a simplified interface to a library, a framework, or any other complex set of
classes
Facade pattern maigh provide limited functionality
A facade might provide limited functionality in comparison to working
with the subsystem directly. However, it includes only those
features that clients really care about
What is the purpose of additional facade
An Additional Facade class can be created to prevent polluting a single facade with unrelated features that might make it yet
another complex structure. Additional facades can be used by
both clients and other facades
Provide a definition for Flyweight pattern
Structural design pattern that lets you fit more objects into the available amount of RAM by sharing common parts of state between multiple objects instead of keeping all of the data in each object
State of an object with constant data of which lives within the object; other objects can only read it, not change it.
Intrinsic state
The object’s state, often altered “from
the outside” by other objects, is called
Extrinsic state
What you can say about Flyweight and immutability
You have to make sure that its state can’t be modified.
A flyweight should initialize its state just once, via constructor parameters. It shouldn’t expose any setters or public fields to
other objects.
What you can say about Flayweight fatory
It is teh factory method pattern. The method accepts the intrinsic state of the desired flyweight
from a client, looks for an existing flyweight object matching this
state, and returns it if it was found. If not, it creates a new fly-
weight and adds it to the pool
Provide a definition for Proxy pattern.
Proxy is a structural design pattern that lets you provide a
substitute or placeholder for another object. A proxy controls
access to the original object, allowing you to perform
something either before or after the request gets through to
the original object
What is an alternative implementation of proxy when extracting interface is not possible
Make the proxy a subclass of the service class, and this way it’ll inherit the interface of the service
Service class should be passed to Proxy via constructor or should be created internally be Proxy
Usually, proxies create and manage the whole life cycle of their servers. In rare occasions, a service is
passed to the proxy via a constructor by the client