𝗪𝗵𝗲𝗻 𝘁𝗼 𝘀𝗲𝗹𝗲𝗰𝘁 𝗗𝗲𝘀𝗶𝗴𝗻 𝗣𝗮𝘁𝘁𝗲𝗿𝗻?
Choosing the correct design pattern in software engineering is critical to practical problem-solving. This guide simplifies the process, helping you decide between patterns based on specific needs.
To select a pattern, we must first go through the problem identification. If the problem is related to:
🔸 Object Creation? → Creational Patterns
🔸 Object Assembly? → Structural Patterns
🔸 Object Interactions? → Behavioral Patterns
𝟭. 𝗖𝗿𝗲𝗮𝘁𝗶𝗼𝗻𝗮𝗹 𝗣𝗮𝘁𝘁𝗲𝗿𝗻𝘀
🔹 Singleton: This is used when a single instance of a class is needed. Some examples are logging and database connections.
🔹 Factory Method: Decouple object creation from usage. For example, you create different types of database connections based on configuration.
🔹 Abstract Factory: Create families of related objects. For example, I build parsers for different file formats (e.g., JSON, XML, CSV).
🔹 Builder: Constructing complex objects step by step. For example, if you need to create a complex domain object.
🔹 Prototype: Creating duplicate objects and reusing cached objects to reduce database calls.
𝟮. 𝗦𝘁𝗿𝘂𝗰𝘁𝘂𝗿𝗮𝗹 𝗣𝗮𝘁𝘁𝗲𝗿𝗻𝘀
🔹 Adapter: Make incompatible interfaces compatible. For example, it integrates a new logging library into an existing system that expects a different interface.
🔹 Composite: Represent part-whole hierarchies. For example, graphic objects in a drawing application can be grouped and treated uniformly
🔹 Proxy: Control access to objects. For example, lazy loading of a high-resolution image in a web application.
🔹 Decorator: Dynamically add/remove behavior. For example, we are implementing compression or encryption on top of file streams.
🔹 Bridge: Decouple abstraction from implementation. For example, I am separating platform-specific code from core logic.
𝟯. 𝗕𝗲𝗵𝗮𝘃𝗶𝗼𝗿𝗮𝗹 𝗣𝗮𝘁𝘁𝗲𝗿𝗻𝘀
🔹 Strategy: Define a family of algorithms. These algorithms allow users to choose different sorting or compression algorithms.
🔹 Observer: Maintain a consistent state by being notified of changes and, for example, notifying subscribers of events in a messaging system.
🔹 Command: Encapsulate a request as an object. For example, I implement undo/redo functionality in text or image editor.
🔹 State: Encapsulate state-specific behavior. For example, we are handling different states of a user interface element (e.g., enabled, disabled, selected).
🔹 Template Method: Define the skeleton of an algorithm in operation, deferring some steps to subclasses and implementing a base class for unit testing with customizable setup and teardown steps.
In the end, we came up with the pattern we needed.
To learn more about it, check out my free book on Design Patterns in the comments.
#softwaredesign
I've said this before, but could we all please drop the idea that software development is an Engineering discipline? I just don't see it, and there's a huge amount if dysfunction that stems from that thinking. What we do literally has no overlap with any true engineering discipline. (And no, don't start on straw men like "creativity". If that's a common ground, then dance is an engineering discipline.) What we do involves essentially no mathematical analysis of anything. We are not doing math.
If you're building a system that requires math, then the math is part of the _domain_, not the development process.
Ofrecer resistencia a la colocación de una rampa es un acto de discafobia institucional, fruto de mentes capacitistas.
Ni el Papa, que va en silla de ruedas, podría entrar a la catedral.
¿De qué lado estaría Jesús?
@AytoAlcalaH@javiRpalacios@PSOE@ILUNION
Hoy es el día del año en que hemos consumido los recursos ecológicos equivalentes al tamaño de nuestro planeta Tierra. El resto del año consumiremos más allá de nuestras posibilidades (o los recursos de un planeta q debería ser mayor).
#OvershootDay
https://t.co/ZZkOEVQYPI
Los escarabajos de productos almacenados dañan los alimentos, las materias primas y contaminan los productos elaborados a través del deterioro o una infección micótica . Algunos atacan a los granos enteros. Otros siguen el daño inicial como plagas secundarias. #PlagaDelMes
!Madrid necesita sangre (0, A y AB) y es urgente que sus candidatos nos den ejemplo!
Pídeselo a tu candidato con el Hastag:
#MiCandidatoDonaSangre
¡y firma también la petición! https://t.co/D0RbVAbkus a través de @change_es
Y si en 2021 los diputados pueden votar desde casa: ¿Qué problema hay en que lo hagan también los ciudadanos?
¿Acaso no sería más democrático aumentar la participación y la presencia de los ciudadanos en la política?
#LiberaTuVoto
Dices que quieres una revolución
Vaya, ya sabes
Todos queremos cambiar el mundo.
Me dices que es evolución
Vaya, ya sabes
Todos queremos cambiar el mundo
Pero cuando hablas de la destrucción
Sabes que no puedes contar conmigo
Lennon / Mccartney
#Hasel
¿Por qué no subimos el cómputo de años para calcular LAS PENSIONES DE NUESTROS DIPUTADOS de 8 a 25 años (igualándolas a las de los demás)?
#Espabilate o ¿eres Kasta?
Ni para el #PP, ni para el #PSOE
Qué los jueces elijan al #CGPJ, sin presiones políticas!
Es hora de actuar o lo lamentarnos en el futuro. Hazlo por tí, hazlo por el futuro!
FIRMA Y DIFUNDE:
https://t.co/Qsngl00H7c
No dejes que las disputas de nuestros políticos nos hagan perder los #140000Millones que España necesita para salir de la crisis. Nos jugamos nuestro futuro.
!AYÚDANOS firmando la petición! https://t.co/dcaZhpjg7o a través de @change_es