Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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
add comment

1 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.

share|improve this answer
add comment

Your Answer

 
discard

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.