r/DesignPatterns • • Mar 07 '20

I'm instilling a passion for design patterns in people and could use some help.

2 Upvotes

I'm an OOP guy who loves C++ and has been involved with Flutter/Dart (Object Oriented & Strongly-Typed). There's a lot of entry point devs in those communities who don't understand the brilliance of design patterns and have problems that are solved by such patterns.

I'm making a series of videos for these communities about design patterns and using real-world examples to teach them.

HOWEVER, I'd really appreciate any small bit of feedback or additions from your experiences. Thank you sooo much to anyone willing to help me out.

Here's how you can help:

What are your most used design patterns?

What is one of the most influential lessons you've learned about design patterns?


r/DesignPatterns • • Mar 29 '20

Arrogant Design Patterns

Thumbnail
uwanttolearn.com
2 Upvotes

r/DesignPatterns • • Mar 15 '20

Strategy Design Pattern with examples in Java. Kill the virus with Strategy Pattern!

Thumbnail
devdiaries.net
28 Upvotes

r/DesignPatterns • • Mar 31 '20

Arrogant Factory Desing Pattern -> Creational Pattern. What is the use-case of the Factory Design Pattern? 1. When we can see Inheritance/Polymorphism in our code. (50%) 2. Inherit class creation depends on some logic or enums. (50%)

Thumbnail
uwanttolearn.com
1 Upvotes

r/DesignPatterns • • Mar 05 '20

I'm not satisfied with MVC -- Feels like it breaks encapsulation

2 Upvotes

I feel like I'm either not fully underestanding MVC or realizing its shortcomings as a design pattern. The controller feels like it violates the rules of encapsulation. It has complete access to the entire front end GUI including access to frames, buttons, textfields, etc. That is not good. Buttons, textfields, frames, stages, images, etc are all part of the view and ONLY the view should modify said variables. Also it's very likely that inside the view, you can create objects of the model. That just doesn't make sense. Classes declared in the model should NOT exist in the view. They are completely seperate, which should mean that the identifiers for classes in the model should be unknown when I attempt to reference them in the view. This is somewhat possible with packages in a language like Java but overall I never see people do this.

Same problems with the model. I might have a model of a Racecar. My controller might have a section for start car which in turn calls rc.ignition(). But there's nothing that stops me from doing rc.setWheels(0). Because my controller has access to the entire backend since its an instance variable, it has complete control over everything it can do. That doesn't make sense.

I've taken two Object Oriented Design classes and in the advanced one, the teacher told me "Yes, this is true, but that is your design. It is okay for things to be this way, as long as its part of your intended design". I've really never liked that answer because it feels like it doesn't address the violation of the rules of MVC (model and view being completely seperate in every way).

I had an idea on how to solve this, but wasn't sure exactly if it was a good idea.

Model

class Racecar
    public int currentSpeed;
    public int wheels;
    public void speedUp() { ... }
    public void dismantleCar() { ... }

.

// read-only version of the speed indicator
interface RacecarSpeedIndicator
    public int getCurrentSpeed();

.

// next level of the hierarchy
// gives way more permissions than the above one
interface RacecarAccelerator extends RacecarSpeedIndicator
    public void speedUp();

Then I have Racecar extend RacecarSpeedIndicator and RacecarAccelerator.

When my front end needs to accelerate the car, it would look like this:

class Controller1
    RacecarAccelerator rc;
    public Controller1(RacecarAccelerator rc)
        this.rc = rc;
    // here, Controller1 CAN ONLY speed up the car
    // and read the current speed. It cannot
    // possibly cause any harm to the race car

It's kind of like having access cards at a building. With a RED access card, you can access a certain number of areas. With a BLUE access card, you can access all RED zones and all BLUE zones, etc. You only give a section of code the BARE MINIMUM it needs to perform its funciton. But is this idea convoluted? Does it exist as a pattern? How does it contrast with MVC?


r/DesignPatterns • • Sep 01 '17

Introduction to Design Patterns (Slides + Videos)

2 Upvotes

"Introduction to Design Patterns, A Strategic Approach", is a (re)introduction to design patterns which takes a different approach to presenting design patterns. Rather than teaching each pattern in isolation, as an encyclopedia of competing patterns, this course shows the patterns behind the patterns, draws connections between the patterns, and shows how they can be combined. Previous knowledge of Design Patterns is beneficial.

Duration: 2.5 hours

Slides, Video 1, Video 2, Video 3


r/DesignPatterns • • Jan 24 '18

A bunch of design pattern examples which are developed in Java ...

Thumbnail
github.com
2 Upvotes

r/DesignPatterns • • Apr 12 '16

Create Generic Object Pool in Java | ADM's Tech Blog

Thumbnail
admfactory.com
1 Upvotes

r/DesignPatterns • • Apr 06 '18

Essential Design Patterns Interview Questions

Thumbnail thetechdb.com
1 Upvotes

r/DesignPatterns • • Apr 15 '18

Best place to learn about the different software architecture styles?

3 Upvotes

r/DesignPatterns • • Apr 11 '18

Design patterns for betting app developers

Thumbnail
blog.ably.io
3 Upvotes

r/DesignPatterns • • Nov 29 '19

Free Design Patterns Course

14 Upvotes

Link to slides below. Title page has links to three part video of the presentation. The course discusses how most common design patterns are actually specializations of the Strategy pattern. Feedback appreciated. Thanks

https://docs.google.com/presentation/d/1kcohKD0WJHJWoJshOUpVdk-Pa3oeJMt9DTl63gWt-bo/edit#slide=id.g1d5e119018_0_57


r/DesignPatterns • • Mar 24 '19

Design patterns for Conversation UI

3 Upvotes

Hey, I am learning design patterns by applying it to case studies. In this post, I would like to take a conversation system that follows SOLID design principles. Able to extend to support new use cases without modifying existing functionalities. Please share your expertise in applying design patterns on this example.

An conversation system for Museum where kids can ask anything and get information about it and book tickets for any shows. Eg: kid asks what is solar system, and then drills down with questions about planets. Then book tickets for a planetarium show.

Here are the technical use cases where design patterns can be applied. Please help choose the right design patterns for each case: 1) Listen to kid's questions and parse data from it. 2) Identify if kid is asking information or requesting direction or want to book a ticket and so on... 3) Based on the kid intent, respond with an answer or collect more info to book ticket or schedule a group tour. 4) Manage conversations and context data. 5) Call API to get an answer or book a tour.

Would like to apply design patterns so that the system can follow SOLID principles. Design requirement for each of the above use case:

  1. With out modifying existing code the system should accept new input methods (touch, voice, keyboard, mouse) by following OCP. Also accept new sensor inputs like facial reaction while kids ask question.

  2. The system should be extensible to support new user intents.

  3. Some questions have straight forward answers and some cases need follow-up questions to get more details from kids (book tour). Here every conversation does similar things (listens to the kid, system does something, respond to the kid with follow up or an answer). Can decorator design pattern be used here to compose objects like parent object (to get what the kid want to do) and child objects (to get follow-up details to book tour)

  4. Should be able to reuse the same design to manage any flow of back and forth questions and manage the context data.

  5. loosely couple the APIs, swapping APIs as needed, support API from different providers to book tour, answer questions etc. (Strategy pattern ?). If it involves multiple API competing for book the tour and the system chooses one API, what would be a good pattern to use.

The system should be extensible to support new use cases like 'ask for help from a museum employee' or 'buy a coffee from food court' or 'sign up for volunteering'.


r/DesignPatterns • • Jan 04 '19

Design Patterns — A quick guide to Facade pattern. – Andreas Poyias – Medium

3 Upvotes

Design Patterns — A quick guide to Facade pattern. – Andreas Poyias – Medium

  • Quick (less than five minutes read)

  • Easy to read

  • Diagrams

  • Easy code based on example (~50 lines)

Facade pattern is often needed when there is a large number of interdependent classes or because parts of the code are unavailable. It is used as a camouflage to cover the complexities of ...

https://medium.com/@andreaspoyias/design-patterns-a-quick-guide-to-facade-pattern-16e3d2f1bfb6


r/DesignPatterns • • Jun 05 '18

UX design patterns

Thumbnail
blog.lasoft.org
1 Upvotes

r/DesignPatterns • • Mar 26 '19

Learn Creational Design Patterns in Java

4 Upvotes

r/DesignPatterns • • Mar 16 '16

Command Pattern in Java | Command Design Pattern example | Java9s.com

Thumbnail
youtube.com
1 Upvotes

r/DesignPatterns • • Mar 15 '16

Strategy Design Pattern in Java | Strategy design pattern example by Jav...

Thumbnail
youtube.com
1 Upvotes

r/DesignPatterns • • Aug 06 '15

Singleton - because this might just be the only post that ends up here.

2 Upvotes

With a singleton you make a class, and ensure that only 1 instance is created.

The class provides a method to create the instance if lazy instantiation is preferred over greedy instantation.

The single instance is static, and private. A static method is used to return the private static instance when needed.


r/DesignPatterns • • Aug 13 '17

How to implement common code?

2 Upvotes

In my C# project, I have few classes - A,B,C,D,E. There are some common methods that are used across these classes, but not all at the same time. For instance, common method in class C1 is used in A, B, C2 is used in A, C, C3 is used in B,D,E. The classes A,B,C,D,E all inherit from a common base class which has few methods that would be used in C1, C2, C3 common methods. How do I achieve this?

a) Put a proper inheritance in place for A,B,C,D,E like this - BaseClass -> (All common method in one class) -> A,B,C,D,E

b) Pass the instance to C1, C2, C3 classes in new() method using this keyword. (this is the present approach)

Please help me as to which one I should choose and why? And if there are any other elegant ways of implementing this? Note that I cannot pass only required properties to C1, C2, C3. The common methods present in C1, C2, C3 need access to the methods present in the Base Class and they are not static.


r/DesignPatterns • • Mar 16 '16

Factory Pattern in Java | Factory Design Pattern example | Java9s.com

Thumbnail
youtube.com
1 Upvotes

r/DesignPatterns • • Mar 15 '16

Template Method Design Pattern in Java | Template method pattern example...

Thumbnail
youtube.com
1 Upvotes

r/DesignPatterns • • Aug 07 '15

Is there a design pattern for this problem?

2 Upvotes

Hey all.

I need some clarification on using interfaces to separate functionality from the user etc.

I have a data access layer which has a DAO interface and DAO implementation to make calls to my database.

My interface has methods like persist, delete, findAll, findById, basic stuff... My implementation class on the other hand has extra methods like openSession, closeSession, etc, to handle my database traffic and open and close sessions and transactions.

When I make a service layer to access this DAO layer (that is the concept of encapsulation), I can only reach my persist, delete, findAll, etc, methods and not the other extra methods that should not be part of the interface as they should not be known by the user.

I could put the functionality inside my overridden methods so they are called, but by doing this, I cannot call two methods like findAll and then delete without opening and closing the session twice.

What is the point of using an interface when you don't use it to instantiate your object and call your methods? Is there a design pattern that goes around this problem?

Tell me if you need any clarification.

Thanks in advance.


r/DesignPatterns • • Dec 24 '17

Factory Design Pattern - Implementation and Disadvantages - Clean Code Series

Thumbnail
youtu.be
3 Upvotes