1/88
Flashcards about Design Patterns, Anti-Patterns, and SOLID Principles.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is a design pattern?
A general, reusable solution to a commonly occurring software design problem.
Is a design pattern a ready-made code package?
No, it is a template that a developer can modify and implement for their particular applications.
What are design patterns concerned with?
Application & System Design, Abstractions on top of code, Relationships between classes & other collaborators, Problems that have already been solved.
What are design patterns NOT concerned with?
Algorithms and Specific implementations or classes
What do architecture styles focus on?
Components and how they relate to each other.
What do design patterns focus on?
Low-level code, objects, and classes.
What should you expect from design patterns?
Code, class diagrams, etc.
What should you expect from architecture styles?
Higher level diagrams (component diagrams, activity diagrams, etc.)
What is an anti-pattern?
A design pattern that is ineffective and counterproductive.
What is Spaghetti Code?
Ad hoc software structure that makes it difficult to extend and optimize code; also known as Big Ball of Mud.
What is Lava Flow?
Unready code that is put into production and is added to while still in an unfinished state.
What is Golden Hammer?
Obsessively applying a familiar tool to every software problem.
What is Boat Anchor?
Code that doesn’t do anything is left in the codebase “just in case.”
What is God Class?
One class taking on too many responsibilities.
What is Poltergeist Class?
Useless classes with no real responsibility of their own, often used to just invoke methods in another class or add an unneeded layer of abstraction.
What is a key aspect of a software developer's job?
Understanding existing software, Maintaining software (fixing bugs), and Upgrading (adding new features).
Why are design patterns important in software development?
Design patterns help anticipate change, providing a common language to communicate solutions with other developers.
What question should one ask when deciding to use or not use a design pattern?
When is a design pattern needed/applicable? How can we tell if a pattern is making things better or worse? When should we avoid patterns that will make things worse?
Who are the members of the Gang of Four?
Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides.
What is the importance of the book 'Design Patterns: Elements of Reusable Object-Oriented Software'?
Written in 1994, it is a very influential text in software design.
Who introduced the SOLID Principles?
Robert C. Martin.
What do SOLID principles help developers write?
Software that is easy to understand, modify, and extend.
What do the SOLID principles provide?
A set of guidelines for writing high-quality, maintainable, and scalable software.
What does SRP stand for?
Single Responsibility Principle.
What does OCP stand for?
Open-Closed Principle.
What does LSP stand for?
Liskov Substitution Principle.
What does ISP stand for?
Interface Segregation Principle.
What does DIP stand for?
Dependency Inversion Principle.
What is the Single Responsibility Principle?
A class should have only one reason to change, or in other words, it should have only one responsibility.
What does having too many responsibilities in a class lead to?
Code that is difficult to understand and maintain.
What is the Open-Closed Principle?
Software entities should be open for extension but closed for modification.
What does the Open-Closed Principle promote?
Software extensibility and maintainability.
What is the Liskov Substitution Principle?
Any instance of a derived class should be substitutable for an instance of its base class without affecting the correctness of the program.
What can violating the Liskov Substitution Principle lead to?
Unexpected behavior, bugs, and maintainability issues.
What is the Interface Segregation Principle?
No client should be forced to depend on methods it does not use.
What is the focus of the Interface Segregation Principle?
Designing interfaces that are specific to their client's needs.
What is the Dependency Inversion Principle?
High-level modules should not depend on low-level modules, but both should depend on abstractions.
What are the types of Design Patterns?
Creational, Structural, Behavioural and Concurrency
What are creational design patterns?
Patterns that deal with object creation mechanisms.
What are structural design patterns?
Patterns that deal with organizing objects to form larger structures and provide new functionality.
What are behavioral design patterns?
Patterns that deal with recognizing and realizing common communication patterns between objects.
What are concurrency design patterns?
Patterns that deal with multi-threaded programs.
What is a drawback to typical object creation?
Client must know which class is being created and has complete control over object creation.
What does a creation design pattern allow?
Object creation can be abstracted; Client may not need to know which class to create; Client may not need to know how to create an object.
What can creational patterns facilitate?
Dependency inversion, shifting emphasis away from pure inheritance to composition and interfaces.
What does the Prototype pattern do?
Creates instances of an object by cloning a prototypical instance.
Why is cloning existing objects helpful?
Often computationally cheaper than creating new ones and copies encapsulated attributes.
What are the elements of the Prototype pattern?
Prototype, ConcretePrototype, and Client.
What does the Prototype define?
The interface of cloned objects.
What does the ConcretePrototype do?
Implements the Prototype class.
What does the Client do?
Creates one instance of the ConcretePrototype, then clones it to make any more.
When should you use the Prototype pattern?
When a system should be independent of how its products are created, composed and represented, when a class to be instantiated is selected a run-time or when instances of a class can have have only a few different combinations of state.
What are the pros of Prototype pattern?
You can clone objects without coupling to their concrete classes; You can get rid of repeated initialization code in favor of cloning pre-built prototypes; You can produce complex objects more conveniently; You get an alternative to inheritance.
What are the cons of Prototype pattern?
Cloning complex objects that have circular references might be very tricky.
What does the Factory pattern do?
Replaces direct object construction calls (using the new operator) with calls to a special factory method.
What are objects returned by a factory method referred to as?
Products.
What are the elements of the Factory pattern?
Product, ConcreteProduct, Factory, and ConcreteFactory.
What is the role of the Product?
Defines the interface of objects created by the factory.
What is the role of the ConcreteProduct?
Implements the Product interface.
What is the role of the Factory?
Declares a factory method that returns a Product. May have other methods that use the factory method.
What is the role of the ConcreteFactory?
Overrides the factory method to return a ConcreteProduct.
When should you use the Factory?
When a class can’t anticipate the class of objects it must create or a class wants its subclasses to specify the objects it creates or you want to localise knowledge about object creation.
What are the pros of Factory?
Modular expandability – can create new concrete factories and products without breaking client functionality and delegates object creation responsibilities to a separate class.
What are the cons of Factory?
Requires more classes than just using a straightforward constructor call.
What pattern name is AKA virtual constructor?
Factory Pattern
What does the Abstract Factory pattern provide?
Provides an interface for creating families of related or dependent objects without specifying their concrete classes.
What are the elements of the Abstract Factory pattern?
AbstractProduct, ConcreteProduct, AbstractFactory, ConcreteFactory, and Client.
What is the role of the AbstractProduct?
Interface for products.
What is the role of the ConcreteProduct?
Implements AbstractProduct.
What is the role of the AbstractFactory?
Declares an interface for factories that create AbstractProducts.
What is the role of the ConcreteFactory?
Implements AbstractFactory and creates ConcreteProducts.
What is the role of the Client?
Uses interfaces provided by AbstractFactory and AbstractProduct.
When should you use Abstract Factory?
When a system should be independent of how its products are created or configured with multiple families of products or when you want to provide a class library of products but want to reveal just their interfaces.
What are the pros of Abstract Factory?
You can be sure that the products you’re getting from a factory are compatible with each other and avoids tight coupling between concrete products and client code.
What are the cons of Abstract Factory?
The code may become more complicated than it should be, since a lot of new interfaces and classes are introduced along with the pattern.
What does the Builder pattern do?
Separates the construction of a complex object from its representation.
What are the elements of the Builder pattern?
Product, Builder, ConcreteBuilder, and Director.
What is the role of the Product in the Builder Pattern?
The complex object to be built.
What is the role of the Builder in the Builder Pattern?
The interface for building Products.
What is the role of the ConcreteBuilder in the Builder Pattern?
Implements Builder to construct parts of Product.
What is the role of the Director in the Builder Pattern?
Optional class that coordinates the Builder.
When should you use the Builder pattern?
When the algorithm for creating a complex object should be independent of the parts that make up the object and how they're assembled or when the construction process must allow different representations for the object that's constructed.
What are the pros of Builder?
You can construct objects step-by-step, defer construction steps or run steps recursively and reuse the same construction code when building various representations of products.
What are the cons of Builder?
The overall complexity of the code increases since the pattern requires creating multiple new classes.
What does the Singleton pattern do?
Restricts the instantiation of a class to a single instance.
How to implement a singleton?
Default constructor is made private, use a static creation method that calls the default constructor the first time and return the instance on every subsequent call.
When should you use Singleton?
When there must be exactly one instance of a class, and it must be accessible to clients from a well-known access point.
What are the pros of Singleton?
You can be sure that a class has only a single instance; You gain a global access point to that instance; The singleton object is initialized only when it’s requested for the first time.
What are the cons of Singleton?
The Singleton pattern can mask bad design and globally accessible components can result in tighter coupling, Isn’t future proof and Violates Single Responsibility Principle