How to apply design patterns in this scenario

design-patterns

I want to use design patterns for the following scenario. How to?

I have classes named Person, Employee and Customer and all of them have their own save, update, get and delete methods. Employee and Customer classes are derived from person.
What may be the best way to code?

Best Answer

What you describe is called Active Record pattern. See the article and google for it, then you'll find sample implementations which you can adapt for your scenario. It is basically a Repository pattern implemented in the entity itself.

Active Record is strong in some scenarios, it's the default for Ruby on Rails applications iirc, but it does have its downsides. I suggest you look them up and think about it again. Maybe your domain suits a classical domain model with persistence ignorance (like Hibernate offers) better.

See also this website here for a comparison.

Related Topic