Posts

Showing posts with the label inheritance

Inheritance vs. Strategy Pattern

Image
Clash Royale CLAN TAG #URR8PPP Inheritance vs. Strategy Pattern I'm learning about programming patterns and for our final assignment we were asked to build an "online store". I was thinking about how to model the User which can either be Admin or Customer . User Admin Customer I thought about the Strategy pattern to model each individual User with their particular behaviors. User They don't share any behaviors so far, so the Admin can't addToCart and Customer can't registerNewProduct . Admin addToCart Customer registerNewProduct However, they could share behaviors / methods as the system evolves! Furthermore, the User won't change it's type in run-time. I.e., once you log in as Customer, you can't log back in as Admin. User Even if they shared behaviors such as seeProductList , this could be achieved with good ol' inheritance, right? seeProductList Should I use Strategy, Inheritance or would you recommend another pattern? If you need mor...