Design Patterns and Principles Flashcards
What are Software Design Principles?
Software design principles are guidelines that help developers create scalable, maintainable, and efficient software systems. They help ensure that the software is structured well and can easily adapt to future changes.
What are the key Software Design Principles?
- SOLID Principles 2. DRY (Don’t Repeat Yourself) 3. KISS (Keep It Simple, Stupid) 4. YAGNI (You Aren’t Gonna Need It) 5. Separation of Concerns 6. Composition Over Inheritance
What is the SOLID principle?
SOLID is an acronym representing five design principles that improve software design and development:
1. Single Responsibility Principle (SRP)
2. Open/Closed Principle (OCP)
3. Liskov Substitution Principle (LSP)
4. Interface Segregation Principle (ISP)
5. Dependency Inversion Principle (DIP)
What is the Single Responsibility Principle (SRP)?
A class should have only one reason to change, meaning it should only have one responsibility or job.
What is the Open/Closed Principle (OCP)?
Software entities (classes, modules, functions) should be open for extension but closed for modification, meaning that new functionality should be added without altering existing code.
What is the Liskov Substitution Principle (LSP)?
Objects of a superclass should be replaceable with objects of a subclass without affecting the functionality of the system.
What is the Interface Segregation Principle (ISP)?
Clients should not be forced to depend on interfaces they do not use, promoting the design of small, specific interfaces rather than large, general ones.
What is the Dependency Inversion Principle (DIP)?
High-level modules should not depend on low-level modules. Both should depend on abstractions. Abstractions should not depend on details. Details should depend on abstractions.
What is DRY (Don’t Repeat Yourself)?
The DRY principle emphasizes avoiding code duplication by creating reusable functions or modules, improving maintainability and reducing errors.
What is KISS (Keep It Simple, Stupid)?
The KISS principle promotes simplicity in design and implementation, suggesting that systems should be designed in the simplest way possible without unnecessary complexity.
What is YAGNI (You Aren’t Gonna Need It)?
The YAGNI principle advises developers to focus only on what is necessary for the current iteration and avoid adding functionality that may not be needed in the future.
What is Separation of Concerns?
The principle of separating a software system into distinct sections, each responsible for a specific aspect of functionality, making the system easier to maintain and scale.
What is Composition Over Inheritance?
Composition over inheritance is the design principle that encourages using object composition (creating classes with objects of other classes) rather than relying on class inheritance for extending functionality.
What are Design Patterns?
Design patterns are reusable solutions to common software design problems. They are proven, best-practice solutions that can be applied to specific design challenges.
What are the types of Design Patterns?
- Creational Patterns 2. Structural Patterns 3. Behavioral Patterns
What are Creational Design Patterns?
Creational design patterns deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. Examples include Singleton, Factory Method, and Abstract Factory.
What is the Singleton Pattern?
The Singleton pattern ensures that a class has only one instance and provides a global point of access to that instance.
What is the Factory Method Pattern?
The Factory Method pattern defines an interface for creating objects, but lets subclasses alter the type of objects that will be created.
What is the Abstract Factory Pattern?
The Abstract Factory pattern provides an interface for creating families of related or dependent objects without specifying their concrete classes.
What are Structural Design Patterns?
Structural design patterns focus on how to compose classes and objects to form larger structures while keeping the system flexible and efficient. Examples include Adapter, Composite, and Decorator patterns.
What is the Adapter Pattern?
The Adapter pattern allows incompatible interfaces to work together by wrapping one interface with another that is compatible with the target system.
What is the Composite Pattern?
The Composite pattern allows you to compose objects into tree-like structures to represent part-whole hierarchies, making it easier to treat individual objects and compositions uniformly.
What is the Decorator Pattern?
The Decorator pattern allows behavior to be added to individual objects, dynamically, without affecting the behavior of other objects from the same class.
What are Behavioral Design Patterns?
Behavioral design patterns deal with how objects interact and communicate with each other. Examples include Observer, Strategy, and Command patterns.