Love and Hate for 36 Object-Oriented Design Patterns
We all know what design patterns and anti-patterns are, and probably have a love/hate relationship. They're great for letting us write code, but we abhor seeing non-coders coding. Here's a fun romp through design patterns and anti-patterns, with why each is awesome or the bane of our existence.
Join the DZone community and get the full member experience.Join For Free
design patterns are...come on, you know what they are. they are something we love and hate . we love them because they let us write code without thinking. we hate them when we see the code of someone who is used to writing code without thinking. am i wrong? now, let me try to go through all of them and show you how much i love or hate each one. follow me, in alphabetic order.
abstract factory . it's ok.
adapter . good one!
bridge . good one!
builder . terrible concept, since it encourages us to create and use big, complex objects. if you need a builder, there is already something wrong with your code. refactor it so any object is easy to create through its constructors.
chain of responsibility . seems fine.
command . it's ok.
facade . bad idea. in oop, we need objects and only objects, not facades for them. this design pattern is very procedural in its spirit since a facade is nothing more than a collection of procedures .
factory method . this one seems ok.
flyweight . it's a workaround, as i see it, so it's not a good design pattern. i would recommend you not use it unless there is a really critical performance issue. but calling it a design pattern ... no way. a fix for a performance problem in java? yes.
lazy initialization . it's ok.
mediator . i don't like it. even though 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 objects communicate directly? because they are too complex? make them smaller and simpler, rather than inventing these mediators.
module . if wikipedia is right about this pattern, it's something even more terrible than the singleton.
multiton . really bad idea. same as singleton.
object library . it's good.
object pool . good one.
prototype . good idea, but what does it have to do with oop?
proxy . good one.
raii . this is a really good one, and i highly recommend you use it.
singleton . it's the king of all anti-patterns. stay away from it at all costs.
specification . it's ok.
strategy . a good one.
i have nothing against concurrency patterns either; they are all good since they have almost nothing to do with object-oriented programming.
if you know some other design (anti-)patterns, let me know in the comments below. i'll add them here.
Published at DZone with permission of Yegor Bugayenko. See the original article here.
Opinions expressed by DZone contributors are their own.