Love and Hate for 36 object oriented design templates


design templates

are … come on, you know what they are. they are something that we

love

and

to hate

. we love them because they allow us to write code without thinking. you hate them when you see the code of someone who is used to writing code without thinking. Am I wrong? now let me try to go through them all and show you how much I love or hate each of them. follow me, in alphabetical order.

the brilliant (1980) by stanley kubrick


abstract factory

. it’s good.


adapter

. Well!


bridge

. Well!


builder

. terrible concept, because it encourages us to create and use large, complex objects. if you need a constructor, there is already something wrong with your code. refactor it so that any object is easy to create via its constructors.


chain of responsibility

. look good.


order

. it’s good.


composite

. Well; to verify

this

too much.


decorator

. my

favorite

a. I highly recommend you to use it.


facade

. bad idea. in oop, we need objects and only objects, not facades for them. this design pattern is very procedural in its mind since a facade is nothing more than a collection of

procedures

.


factory method

. this one looks ok.


flyweight

. it’s a workaround, as i see it, so it’s not a good design pattern. I recommend that you don’t use it unless there is a really critical performance issue. but calling it a design template … no way. a fix for a performance problem in java? Yes.


front controller

. terrible idea, as well as the whole

mvc

. he is very

procedural

, that is why.


interpreter

. it’s good, but i

do not like

the name. “expression” would be a much better alternative.


iterator

. bad idea, because it is mutable. it would be much better to have

unchanging

“cursors”.


lazy initialization

. it’s good.


marker pen

. this is a terrible idea, with reflection and

type molding

.


mvc

. bad idea, because it’s very procedural.

controllers

are the key broken element of this concept. we need real objects, not procedural controllers.


mediator

. I do not like it. although it sounds like a technique for decreasing complexity and coupling, it is not really object oriented. who is this mediator? just a “channel” between objects? why shouldn’t the objects communicate directly? because they are too complex? make them smaller and simpler, rather than inventing these mediators.


memento

. this idea implies that objects are

mutable

, which I am against in general.


module

. if wikipedia is correct on this model, it is something even more terrible than the singleton.


multitonne

. really bad idea. same as singleton.


null object

. Well. besides, see

why null is bad


object library

. It’s good.


object pool

. Well.


observer

. the idea is good, but the name is bad because it

ends with -er

. a much better one would be “source” and “target”. the source generates events and the target listens to them.


elm

. it is terrible and “offensive”; Check

this

outside.


prototype

. great idea, but what does that have to do with oop?


Proxy

. Well.


raii

. it’s a very good one, and I highly recommend you to use it.


servant

. a very bad idea, because it is very

procedural

.


singleton

. he is the king of all anti-models. stay away from it at all costs.


specification

. it’s good.


state

. although this is not implied, I think in most cases using this model results in mutability, a feature of the code that I usually follow.

versus

.


strategy

. A voucher.


model method

. looks good, as long as you keep class

final

.


visitor

. one rather

procedural

concept that treats objects like data structures, which we can manipulate.

I have nothing against

simultaneity models

That is; they are all

Well

because they have almost nothing to do with object oriented programming.

if you know of any other (anti-) design patterns let me know in the comments below. I will add them here.


Source link

Previous Sea Sponge's "structural principles" inspire the "design strategy"
Next Design the machines that will design the strategy

No Comment

Leave a reply

Your email address will not be published. Required fields are marked *