Design Patterns in Software Engineering

slide1 l.w
1 / 18
Embed
Share

Design patterns in software engineering are general, reusable solutions to commonly occurring problems within a given context in software design. They provide structured approaches to solving problems and are considered best practices for programmers. This includes patterns like Singleton, Builder, Factory, Abstract Factory, and Dependency Inversion. These patterns aim to streamline the design process and improve code quality by promoting efficient solutions to design problems.

  • Design Patterns
  • Software Engineering
  • Reusable Solutions
  • Best Practices
  • Programming

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Advanced Programming Advanced Programming

  2. Design Patterns Design Patterns In software engineering, a software design pattern is a general, reusable solution to a commonly occurring problem within a given context in software design. It is a description or template for how to solve a problem that can be used in many different situations. Design patterns are formalized best practices that the programmer can use to solve common problems when designing an application or system. Object-oriented design patterns typically show relationships and interactions between classes or objects, without specifying the final application classes or objects that are involved. Some patterns can be rendered unnecessary in languages that have built-in support for solving the problem they are trying to solve, and object-oriented patterns are not necessarily suitable for non-object-oriented languages. Design patterns may be viewed as a structured approach to computer programming intermediate between the levels of a programming paradigm and a concrete algorithm. https://en.wikipedia.org/wiki/Software_design_pattern

  3. Singleton Builder Creational Creational Design Patterns Design Patterns Factory Abstract Factory Dependency Inversion

  4. Ensure they only have one instance Provide easy access to that instance Singleton Singleton Control their instantiation (for example, hiding the constructors of a class)

  5. Singleton UML Singleton UML

  6. object Singleton { val sampleVar: Int = 5 Singleton Singleton Example in Example in Kotlin Kotlin fun sampleFun() { print("Sample print") } }

  7. How can a class (the same construction process) create different representations of a complex object? Builder Builder How can a class that includes creating a complex object be simplified?

  8. Builder UML Builder UML

  9. data class AppRec(var ui: String, var logic: String, var db: String) { class Builder { private lateinit var ui: String private lateinit var logic: String private lateinit var db: String Builder Builder Example in Example in Kotlin 1/2 Kotlin 1/2 fun setUI(ui: String): Builder { this.ui = ui return this } fun build(): AppRec { return AppRec(ui, logic, db) } } }

  10. Usage Usage var app = AppRec .Builder() .setUI("Demo UI") .setLogic("Demo Logic") .setDB("Demo DB").build() Builder Builder Example in Example in Kotlin 1/2 Kotlin 1/2

  11. How can an object be created so that subclasses can redefine which class to instantiate? Factory Factory How can a class defer instantiation to subclasses?

  12. Factory UML Factory UML

  13. fun appInit(appType: String): AppRec { return when (appType) { "DemoApp" -> demoApp() "AlphaApp" -> alphaApp() "betaApp" -> betaApp() "productionApp" -> productionApp() else -> betaApp() } } Factory Factory Example in Example in Kotlin Kotlin

  14. How can an application be independent of how its objects are created? Abstract Abstract Factory Factory How can a class be independent of how the objects it requires are created? How can families of related or dependent objects be created?

  15. Abstract Abstract Factory UML Factory UML

  16. How can a class be independent from the creation of the objects it depends on? Dependency Dependency Injection Injection How can an application, and the objects it uses support different configurations? How can the behavior of a piece of code be changed without editing it directly?

  17. Dependency Dependency Injection UML Injection UML

  18. Multiton Prototype Extra Creational Extra Creational Design Patterns Design Patterns Object Pool Lazy Initialization Resource Acquisition Is Initialization

More Related Content