Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Principles Behind Design Patterns

The Principles Behind Design Patterns

This lecture focuses on basic introduction to design patterns with priciples. Rather than just learning patterns in isolation, we discussed why they exist and how they solve real-world software challenges.

Related quiz is available at: https://forms.gle/26wb53KLZsg1Dx1s7
Source code: https://github.com/nishanc/DesignPatternsDemo

Conducted at the Faculty of Information Technology of University of Moratuwa, Sri Lanka on 24/03/2025

Nishan Chathuranga

March 24, 2025
Tweet

More Decks by Nishan Chathuranga

Other Decks in Programming

Transcript

  1. WHAT ARE DESIGN PATTERNS? • Design patterns are proven, reusable

    solutions to common problems in software design. • Originated from the book Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides (the "Gang of Four"). • Design patterns provide a shared language for developers to communicate efficiently.
  2. TYPES OF DESIGN PATTERNS CREATIONAL STRUCTURAL Creational patterns deal with

    object creation mechanisms, trying to create objects in a manner suitable for the situation Structural patterns are concerned with object composition, allowing objects to form larger structures or adapt to new functionalities by composing objects. Behavioral patterns focus on the interactions and communication between objects, defining how they collaborate and operate together. BEHAVIORAL
  3. MAINTAINABILITY WHY DESIGN PATTERNS Patterns save time by solving common

    problems with tested, efficient approaches. Design patterns promote code reuse, reducing the need to reinvent solutions. Patterns improve code structure, making it easier to maintain and evolve. Helps in creating software that can adapt to changing requirements without major refactoring. PROBLEM-SOLVING EFFICIENCY REUSABILITY FLEXIBILITY
  4. PATTERNS DESIGN PRINCIPLES VS DESIGN PATTERNS Design patterns are reusable

    solutions to common problems in software design. They provide a template or blueprint for solving specific design issues in object- oriented programming. Design principles are fundamental guidelines that help in creating well-structured, maintainable, and flexible software. They are broad concepts that promote good software design practices. PRINCIPLES • SOLID Principles: A set of five principles (Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion) that help in writing scalable and maintainable object- oriented code. • DRY (Don’t Repeat Yourself): Encourages eliminating duplication in code by abstracting common functionality. • KISS (Keep It Simple, Stupid): Advocates for simplicity in design.
  5. OPEN-CLOSED PRINCIPLE In object-oriented programming, the open–closed principle (OCP) states

    "software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification"
  6. OPEN-CLOSED PRINCIPLE ❖ You don’t need to re-invent the wheel:

    as the principle states, the code you and your team are working on is open for extension. This means if you’re following the open-closed principle, you don’t need to reinvent the wheel (and rebuild everything) when you want to add new features. ❖ You focus on what is necessary: as the OCP states, your code is closed for modification. It means you can add new features without performing too much editing on the existing code, or none at all. This can help you and your team members focus on what is necessary when it’s time to implement new functionalities.
  7. BENEFITS OF USING DESIGN PATTERNS Common vocabulary enhances collaboration between

    team members. Simplifies the design process by abstracting complex details. Leverages best practices developed through years of software development experience. IMPROVED COMMUNICATION REDUCED COMPLEXITY PROVEN SOLUTIONS Patterns make it easier to update and modify software in a consistent way. EASIER REFACTORING
  8. CONCLUSION • Design patterns are not a one-size-fits-all solution but

    offer a flexible toolkit. • Encourages their use in everyday coding to solve typical problems in a systematic way. • Real-world examples of applying patterns in frameworks, libraries, and applications (e.g., Model-View-Controller in web frameworks).
  9. Thank You… Any Questions? nishanc.com/contact nishanc.com/contact A qr code on

    a white background Description automatically generated Test your knowledge © 2025 Design Patterns For Developers by Nishan Wickramarathna is licensed under CC BY 4.0 bit.ly/DesignPatternsQuiz bit.ly/DesignPatternsQuiz