# Design Patterns

**URL:** https://forum.codewithmosh.com/c/design-patterns/13.md

[Latest](https://forum.codewithmosh.com/latest.md) · [Categories](https://forum.codewithmosh.com/categories.md)

---

## [About the Design Patterns category](https://forum.codewithmosh.com/t/about-the-design-patterns-category/24)

<div class="topic-metadata">

**Author:** [@Mosh](https://forum.codewithmosh.com/u/Mosh)\
**Replies:** 0\
**Last updated:** [October 22, 2020, 10:28pm UTC](https://forum.codewithmosh.com/t/about-the-design-patterns-category/24 "2020-10-22T22:28:49Z")

</div>

---

## [Design patterns without java?](https://forum.codewithmosh.com/t/design-patterns-without-java/71108)

<div class="topic-metadata">

**Author:** [@theorion](https://forum.codewithmosh.com/u/theorion)\
**Replies:** 3\
**Last updated:** [February 10, 2025, 8:37am UTC](https://forum.codewithmosh.com/t/design-patterns-without-java/71108 "2025-02-10T08:37:02Z")

</div>

Do you think someone could take this course knowing javascript but not java? I’ve been doing data structures for with javascript in order to learn the concepts it’s pretty decent but sometimes challenging. Overall i’m l…

---

## [COurse clarity regarding design patterns](https://forum.codewithmosh.com/t/course-clarity-regarding-design-patterns/26750)

<div class="topic-metadata">

**Author:** [@Kishore1](https://forum.codewithmosh.com/u/Kishore1)\
**Replies:** 1\
**Last updated:** [May 17, 2024, 5:39pm UTC](https://forum.codewithmosh.com/t/course-clarity-regarding-design-patterns/26750 "2024-05-17T17:39:10Z")

</div>

Hi Mosh , I have a machine coding round interview scheduled from a company ,i have taken up your course for c++ and have completed it , now i wanted to take up design patterns for this interview but it says prerequisite…

---

## [Exercises - Design Patterns](https://forum.codewithmosh.com/t/exercises-design-patterns/24114)

<div class="topic-metadata">

**Author:** [@Seahlolo](https://forum.codewithmosh.com/u/Seahlolo)\
**Replies:** 1\
**Last updated:** [December 18, 2023, 11:41pm UTC](https://forum.codewithmosh.com/t/exercises-design-patterns/24114 "2023-12-18T23:41:08Z")

</div>

I am struggling to find these exercise projects, where are they located? Exercise In the Exercises project, look at the strategy/ChatClient class. This class uses an encryption algorithm to encrypt a message before send…

---

## [Is the Adapter pattern example on TutorialPoint wrong?](https://forum.codewithmosh.com/t/is-the-adapter-pattern-example-on-tutorialpoint-wrong/22744)

<div class="topic-metadata">

**Author:** [@goroot45](https://forum.codewithmosh.com/u/goroot45)\
**Replies:** 0\
**Last updated:** [September 27, 2023, 1:53pm UTC](https://forum.codewithmosh.com/t/is-the-adapter-pattern-example-on-tutorialpoint-wrong/22744 "2023-09-27T13:53:53Z")

</div>

I finished the Adapter pattern, and I also finished the exercise. But now while studying the Adapter pattern on TutorialPoint, I feel like that the pattern is wrongly implemented on that website, am I right? It doesn’t m…

---

## [How to get lecture Videos Transcript](https://forum.codewithmosh.com/t/how-to-get-lecture-videos-transcript/16551)

<div class="topic-metadata">

**Author:** [@Ankit55](https://forum.codewithmosh.com/u/Ankit55)\
**Replies:** 2\
**Last updated:** [November 20, 2022, 1:45am UTC](https://forum.codewithmosh.com/t/how-to-get-lecture-videos-transcript/16551 "2022-11-20T01:45:44Z")

</div>

Please help how to get lecture video notes? Thank you in advance!

---

## [What is the difference between singleton and dependency injection](https://forum.codewithmosh.com/t/what-is-the-difference-between-singleton-and-dependency-injection/11652)

<div class="topic-metadata">

**Author:** [@chady](https://forum.codewithmosh.com/u/chady)\
**Replies:** 2\
**Last updated:** [August 12, 2022, 6:39pm UTC](https://forum.codewithmosh.com/t/what-is-the-difference-between-singleton-and-dependency-injection/11652 "2022-08-12T18:39:10Z")

</div>

is the dependency injection design pattern or respect the design pattern singleton ?

---

## [Flyweight pattern solution: CellContextFactory hash collisions](https://forum.codewithmosh.com/t/flyweight-pattern-solution-cellcontextfactory-hash-collisions/14325)

<div class="topic-metadata">

**Author:** [@jmrunkle](https://forum.codewithmosh.com/u/jmrunkle)\
**Replies:** 0\
**Last updated:** [August 12, 2022, 2:25am UTC](https://forum.codewithmosh.com/t/flyweight-pattern-solution-cellcontextfactory-hash-collisions/14325 "2022-08-12T02:25:42Z")

</div>

There is a mild bug here since the Objects.hash function implemented here does nothing to prevent hash collisions. That is to say, there is no guarantee that two distinct CellContexts would not have the same hash so you …

---

## [Flyweight Pattern: Exercise Solution - Possible Error](https://forum.codewithmosh.com/t/flyweight-pattern-exercise-solution-possible-error/11577)

<div class="topic-metadata">

**Author:** [@billwirz](https://forum.codewithmosh.com/u/billwirz)\
**Replies:** 1\
**Last updated:** [August 12, 2022, 12:16am UTC](https://forum.codewithmosh.com/t/flyweight-pattern-exercise-solution-possible-error/11577 "2022-08-12T00:16:18Z")

</div>

Really enjoying the design patterns courses. As I was carefully looking at the Flyweight Pattern exercise solution, I noticed in SpreadSheet.java that all cells are initialised as follows: private void generateCells(…

---

## [Command Pattern for Undo feature Question](https://forum.codewithmosh.com/t/command-pattern-for-undo-feature-question/7595)

<div class="topic-metadata">

**Author:** [@lily](https://forum.codewithmosh.com/u/lily)\
**Replies:** 2\
**Last updated:** [August 11, 2022, 4:26pm UTC](https://forum.codewithmosh.com/t/command-pattern-for-undo-feature-question/7595 "2022-08-11T16:26:49Z")

</div>

Is anyone confused about Mosh’s implementation of undo using the command pattern? His explanation was that this is better because it’s less expensive but the way he’s implemented the command pattern for undo feature is a…

---

## [Cannot Load Class Error](https://forum.codewithmosh.com/t/cannot-load-class-error/10475)

<div class="topic-metadata">

**Author:** [@jcm10](https://forum.codewithmosh.com/u/jcm10)\
**Replies:** 1\
**Last updated:** [August 11, 2022, 6:02am UTC](https://forum.codewithmosh.com/t/cannot-load-class-error/10475 "2022-08-11T06:02:40Z")

</div>

In VSCode with the Java extension, I am getting this error printed: NOTE: I have never used Java and have yet to get any if it to run.

---

## [Command Pattern Exercise: Using addFirst() method fixes wrong undo order](https://forum.codewithmosh.com/t/command-pattern-exercise-using-addfirst-method-fixes-wrong-undo-order/9506)

<div class="topic-metadata">

**Author:** [@DarkPurpleKnight](https://forum.codewithmosh.com/u/DarkPurpleKnight)\
**Replies:** 1\
**Last updated:** [August 11, 2022, 6:01am UTC](https://forum.codewithmosh.com/t/command-pattern-exercise-using-addfirst-method-fixes-wrong-undo-order/9506 "2022-08-11T06:01:27Z")

</div>

Hi In the Command Pattern, Mosh uses a Deque instead of a List. For adding new objects he uses the add() method, which is available for both the Deque and the List. I did it the same way in the Command Pattern exercise…

---

## [Visitor Pattern](https://forum.codewithmosh.com/t/visitor-pattern/8761)

<div class="topic-metadata">

**Author:** [@Oliver](https://forum.codewithmosh.com/u/Oliver)\
**Replies:** 1\
**Last updated:** [August 11, 2022, 5:51am UTC](https://forum.codewithmosh.com/t/visitor-pattern/8761 "2022-08-11T05:51:38Z")

</div>

Why use an interface for the htmlNode class and not instead an abstract class with the implementation for the execute method? So you can extend the abstract htmlNode class and have the logic from the execute method?

---

## [Observer Pattern: Subject class is not abstract](https://forum.codewithmosh.com/t/observer-pattern-subject-class-is-not-abstract/8643)

<div class="topic-metadata">

**Author:** [@leonels](https://forum.codewithmosh.com/u/leonels)\
**Replies:** 2\
**Last updated:** [August 11, 2022, 5:14am UTC](https://forum.codewithmosh.com/t/observer-pattern-subject-class-is-not-abstract/8643 "2022-08-11T05:14:02Z")

</div>

I noticed in the “Observer Pattern: Solution video” Mosh mentioned the Subject class (DataSource class) is an abstract class. But in the following “Implementation” video he does not make the Subject class abstract, none …

---

## [OPINION: Builder pattern is not explained correctly](https://forum.codewithmosh.com/t/opinion-builder-pattern-is-not-explained-correctly/8094)

<div class="topic-metadata">

**Author:** [@aderchox](https://forum.codewithmosh.com/u/aderchox)\
**Replies:** 1\
**Last updated:** [August 11, 2022, 1:48am UTC](https://forum.codewithmosh.com/t/opinion-builder-pattern-is-not-explained-correctly/8094 "2022-08-11T01:48:46Z")

</div>

Although Mosh’s course on Design Patterns is really great and I’d recommend it to everyone, I believe what he has taught as the Builder pattern is actually the Strategy pattern. The correct explanation of the Builder pa…

---

## [Sharing my Memento Exercise](https://forum.codewithmosh.com/t/sharing-my-memento-exercise/7351)

<div class="topic-metadata">

**Author:** [@lily](https://forum.codewithmosh.com/u/lily)\
**Replies:** 1\
**Last updated:** [August 10, 2022, 11:41pm UTC](https://forum.codewithmosh.com/t/sharing-my-memento-exercise/7351 "2022-08-10T23:41:05Z")

</div>

Hello everyone! I have a slightly different implementation than Mosh’s and wondering if anyone can give me feedback on mine? So what I did was I am treating Document to hold current state and only add prevStates to the …

---

## [Philosophy of createState() in Originator class in Memento Pattern](https://forum.codewithmosh.com/t/philosophy-of-createstate-in-originator-class-in-memento-pattern/3596)

<div class="topic-metadata">

**Author:** [@Ahmed1](https://forum.codewithmosh.com/u/Ahmed1)\
**Replies:** 1\
**Last updated:** [August 10, 2022, 11:31pm UTC](https://forum.codewithmosh.com/t/philosophy-of-createstate-in-originator-class-in-memento-pattern/3596 "2022-08-10T23:31:12Z")

</div>

Hello Guys. I’ve question about the philosophy of createState() in Originator class in Memento Pattern. Mosh said: now that Editor(Originator) class no longer stores EditorState(Memento) objects internally, we should …

---

## [StatePattern Canvas example](https://forum.codewithmosh.com/t/statepattern-canvas-example/3081)

<div class="topic-metadata">

**Author:** [@Kannans89](https://forum.codewithmosh.com/u/Kannans89)\
**Replies:** 1\
**Last updated:** [August 10, 2022, 11:20pm UTC](https://forum.codewithmosh.com/t/statepattern-canvas-example/3081 "2022-08-10T23:20:50Z")

</div>

Hello , I have a doubt to clarify the Canvas and the tools example given by Mosh looks like strategy pattern ? Correct me if I am wrong. There is no state transitions happening in the pattern and the states are set from …

---

## [Strange Implentation of Memento pattern in Design Course](https://forum.codewithmosh.com/t/strange-implentation-of-memento-pattern-in-design-course/274)

<div class="topic-metadata">

**Author:** [@clarkkozak](https://forum.codewithmosh.com/u/clarkkozak)\
**Replies:** 7\
**Last updated:** [April 5, 2022, 2:02pm UTC](https://forum.codewithmosh.com/t/strange-implentation-of-memento-pattern-in-design-course/274 "2022-04-05T14:02:12Z")

</div>

Hello all! I’m so surprised to see the difference in the Exercise and the Implementation of the memento pattern. This really doesn’t seem right. I haven’t continue the rest of the course yet; however, I wanted to sure t…

---

## [Behavioral Patterns - Missing pattern](https://forum.codewithmosh.com/t/behavioral-patterns-missing-pattern/2225)

<div class="topic-metadata">

**Author:** [@vivek](https://forum.codewithmosh.com/u/vivek)\
**Replies:** 1\
**Last updated:** [March 17, 2022, 2:34pm UTC](https://forum.codewithmosh.com/t/behavioral-patterns-missing-pattern/2225 "2022-03-17T14:34:45Z")

</div>

Behavioral Pattern is missing Interpreter pattern, also there are errors in the summary document given in the end e.g. Facade and Flyweight both have same description and Template pattern is missing from first page.

---

## [Design Patterns Part 3?](https://forum.codewithmosh.com/t/design-patterns-part-3/1433)

<div class="topic-metadata">

**Author:** [@jes](https://forum.codewithmosh.com/u/jes)\
**Replies:** 5\
**Last updated:** [August 4, 2021, 4:44pm UTC](https://forum.codewithmosh.com/t/design-patterns-part-3/1433 "2021-08-04T16:44:10Z")

</div>

Where can I find the Ultimate design patterns part 3?

---

## [Please make design patterns part 3 course](https://forum.codewithmosh.com/t/please-make-design-patterns-part-3-course/4349)

<div class="topic-metadata">

**Author:** [@VishnuVardhan](https://forum.codewithmosh.com/u/VishnuVardhan)\
**Replies:** 1\
**Last updated:** [April 24, 2021, 4:08am UTC](https://forum.codewithmosh.com/t/please-make-design-patterns-part-3-course/4349 "2021-04-24T04:08:59Z")

</div>

Hi Mosh, I am eagerly waiting for the design patterns part 3 course, please make it as soon as possible

---

## [Convert code Java to c#](https://forum.codewithmosh.com/t/convert-code-java-to-c/742)

<div class="topic-metadata">

**Author:** [@ahmed](https://forum.codewithmosh.com/u/ahmed)\
**Replies:** 1\
**Last updated:** [January 20, 2021, 2:49am UTC](https://forum.codewithmosh.com/t/convert-code-java-to-c/742 "2021-01-20T02:49:37Z")

</div>

Hello, How i can use this code on C#: public SignUpDialogBox() { usernameTextBox.addEventHandler(this::controlChanged); passwordTextBox.addEventHandler(this::controlChanged); agreeToTermsCheckBox.addEventHandler(this…

---

## [Memento pattern exercise](https://forum.codewithmosh.com/t/memento-pattern-exercise/1746)

<div class="topic-metadata">

**Author:** [@octopussy](https://forum.codewithmosh.com/u/octopussy)\
**Replies:** 4\
**Last updated:** [January 10, 2021, 10:04pm UTC](https://forum.codewithmosh.com/t/memento-pattern-exercise/1746 "2021-01-10T22:04:49Z")

</div>

In the solution of the memento pattern exercise, Mosh is using an ArrayDeque. But shouldn’t the pop method be removing the first item, while the task is to “undo” which means that states should be removed from the end?

---

## [Where is the Exercise project?](https://forum.codewithmosh.com/t/where-is-the-exercise-project/1171)

<div class="topic-metadata">

**Author:** [@chkdsk](https://forum.codewithmosh.com/u/chkdsk)\
**Replies:** 3\
**Last updated:** [December 29, 2020, 11:25pm UTC](https://forum.codewithmosh.com/t/where-is-the-exercise-project/1171 "2020-12-29T23:25:02Z")

</div>

Hi there, The exercise slides refer to an Exercise project which presumably has some code already. If this is so, where may I find this? Thank you!

---

## [For the design pattern tutorial](https://forum.codewithmosh.com/t/for-the-design-pattern-tutorial/621)

<div class="topic-metadata">

**Author:** [@fangye100](https://forum.codewithmosh.com/u/fangye100)\
**Replies:** 1\
**Last updated:** [November 11, 2020, 5:44am UTC](https://forum.codewithmosh.com/t/for-the-design-pattern-tutorial/621 "2020-11-11T05:44:43Z")

</div>

hi, dear Mosh I am one of your coding learners, started from the C# series tutorial which are really helpful, so I just finished your design pattern tutorial to step forward to a better programmer, the tutorial used jav…
