Deadly Designs?

SAKSHI SINHA
3 min readFeb 26, 2020

--

Part Three-Flabbergasting Factories

Creational design patterns cannot be complete without a compelling factory

Our factory creates objects. Instances of the class that are somehow similar in features yet divided into categories.

Source: Dmitry Zhart Portfolio

Let’s take the scenario of your mess. Your mess has four caterers that serve the same menu every day but the quality of food and the style of preparation varies(All of them serve sh*t in the name of food, but okay!).

Our unreachable mess in charges decide the menu every month and tell the mess caterers to putRoti(),putSabzi(),putDaal() etc.The caterers obey this abstract system and incorporate these methods.

Incomprehensible?

Let’s understand that by a code snippet:

Our un-approachable abstract in charges cannot be instantiated in the main(Unreachable from students Just like our mess-representatives) and has abstract guidelines(methods) that our caterers will have to override(abide by)

Now my Java noob says:

Source:Me.Me

NoNoNoNo: Interface!=Abstract Class(Interfaces cannot be abstract Class)

Source: Java Concept Of The Day

The caterer after receiving his guidelines abides by these methods putting in his ingredients and cooking techniques to dish out hell to students. Let us see the havoc by a handsome code example:

cat_A class extending the practices set out by the reps

In a similar manner, the other caterers will have to abide by the guidelines(override the methods) and serve the students.

Let’s get an overview of the system by a UML.

The messed up mess!

CONCLUSION

Thus, was the messy story of a messed up mess factory’s reps and caterers. Let’s find out how such a deadly design benefits our boring code-bases.

MANAGABILITY

  • Say our mess was huge and had way too many caterers. Such a system would come handy as our in charge(factory) is acting as a knowledge base to provide all the students the same type of food on paper to ensure fee transparency and equality. However, depending on the caterer a student has taken he/she is served trash of varying degrees, taste and quality.

ABSTRACTION

  • The mess in charges get to live an easy life as they are abstracted from angry students.

SCALABILITY

  • The mess becomes easy to extend and it is easy to fire a caterer

Hope the story helped :)

Looking forward to your feedback

#DeadlyDesigns #AMonthOfPatterns #TrainingYourDesignDragon

--

--