Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If you ever see a factory that makes single objects of one kind, that's basically abuse of the factory pattern.

The purpose of factory is to make groups of related objects that are from parallel, but distinct, inheritance hierarchies.

For instance, to do AES encryption, you might need an AESKey (a kind of Key) and an AESCryptContext (a kind of CryptoContext).

Your code doesn't want to know about the existence of these classes at all, let alone their relationship.

You need some interface where you pass, say, the character string "AES" (or some enumeration, or Lisp symbol or whatever) and you get some object that makes keys and contexts of that kind.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: