Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.