Vitalii Vasylenko
Vitalii Vasylenko

Reputation: 4906

Inheritance design for having similar entities but with different properties

I'm designing a several views, which should show a list of players and their properties, but from different perspectives.

ViewA shows player's: Name, Exp, Skill, Condition
ViewB shows player's: Name, Exp, Skill, Bonus
ViewC shows player's: Name, Exp, Price, Bid amount

Common thing for all views are Name and Exp - so there's a sense to move them to the BaseView. Also, there's a Skill, which is used in 2/3 views and will be probably used in some next views, so it also can be moved to the base view.

The questions are:

What are the recommended practices for this case?

UPD: To make question more generic, assume i have 20 properties and 10 Views, each of them should show, say, 7 different properties. I'm afraid i'll end up with BaseWithSkillExpHpManaBonusView.

Upvotes: 0

Views: 55

Answers (1)

Michael Kapustey
Michael Kapustey

Reputation: 173

If you have 20 properties and 10 Views and each of them should show ~7 different properties, I would recommend you to use decorator pattern.

http://www.dotnet-tricks.com/Tutorial/designpatterns/VRQT130713-Decorator-Design-Pattern---C

In this case you would have smth like IBaseView, BaseView, BaseViewDecorator, HealthDecorator : BaseViewDecorator and so on.

Upvotes: 1

Related Questions