Design Patterns Flashcards
What is a factory?
method that wraps a constructor/methods that create objects
what is an abstract factory?
method that creates objects and doesn’t specify class
what is a builder?
object that can create other objects, can store configurations
what is an injector?
creates/imports target objects and injects them into the target object during creation. Thus, the target object does not create its has-a fields
what is lazy initiation?
defer creating an object until absolutely necessary, commonly a pointer stores the reference to the object and it set to null in the beginning
what is singleton?
only one object for a class. shared across thread/tasks
what is multiton?
multiple but finite objects for a class, stored in a collection (e.g. map) controlled access/allocation
what is an adapter?
converts an interface to another and connects two systems, useful when not possible to change existing structures
what is a bridge?
allows implementations to vary, allows objects to vary
what is a composite?
enables treating members of trees (or graphs) in the same way regardless if there are terminal, middle roots, etc.
what is a twin?
work around for multiple inheritance, clients refer only to one of the two objects directly, depending on their design. Interfaces could be used for further abstraction. Multi-implementation of interfaces is normally allowed.
what is an iterator?
go through all elements of a collection and run a method on each
what is a thread pool?
creates N threads, add tasks in the pools queue and each thread taks the next task from the queue and runs it.
what is read/write lock
allows only one writer to lock and multiple readers can read