Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Poltergeist antipattern example

I'm trying to understand what is Poltergeist antipattern, and how does it differ from Command or Delegate patterns. I've read:

http://en.wikipedia.org/wiki/Poltergeist_(computer_science) http://sourcemaking.com/antipatterns/poltergeists

But didn't understand the difference...

So to make it clear I would like to see the code example of it (I prefer C# or Java languages).

Does anybody have it?

like image 718
Oleg Oshkoderov Avatar asked Oct 09 '12 14:10

Oleg Oshkoderov


People also ask

What is an example of an anti-pattern?

An anti-pattern is an idea of how not to solve it because implementing that idea would result in bad design. An example: a "pattern" would be to use a function for code reuse, an "anti-pattern" would be to use copy-paste for the same.

What does anti-pattern means?

“An anti-pattern is a common response to a recurring problem that is usually ineffective and risks being highly counterproductive.” Note the reference to “a common response.” Anti-patterns are not occasional mistakes, they are common ones, and are nearly always followed with good intentions.

How do you identify anti-patterns?

In an organization, there are three main opportunities to identify anti-patterns: During design reviews, during code reviews and during refactoring of legacy code. Design reviews are a great opportunity to find anti-patterns.


1 Answers

Wikipedia describes the command pattern with:

The command pattern is a behavioural design pattern in which an object is used to represent and encapsulate all the information needed to call a method at a later time. One component can send a command to another specific component, with the assumption that when some condition is met, the command will be fired.

This concept is very like that of a functor in functional programming (A functor is basically a function in a black box, arguments and all)

The poltergeist is described with:

The poltergeist is a short-lived, typically stateless object used to perform initialization or to invoke methods in another class.

Commands are generic and have to be able to contain enough state to be reused. Poltergeists are usually special purpose and exist only to rattle some chairs and make loud noises in the basement, then to disappear. Poltergeists are usually used as a crutch to help construct or initialize an object and are rarely used to share changes in state after construction.

In other words, yes, they are vaguely similar, but poltergeists are inflexible and represent a static action, and commands are generic, can be reusable, and represent a configurable action.

like image 93
Wug Avatar answered Sep 28 '22 20:09

Wug