I have a user class that contains name, email, city, state, zip. This is common to both sub groups of mobile user and web user. the sub group has different methods. Should user be an abstract class and the two sub groups be like so?
Asked
Active
Viewed 160 times
0
-
Your second question isn't very clear. – Alex Lockwood Jun 07 '12 at 01:10
-
Yeah, I took it out. I'll address it later, thanks. – KiloJKilo Jun 07 '12 at 01:12
-
Why not add a `StoreUser()` method to the abstract `Users` and then have your concrete implementations vary in details without exposing __how__ they're being stored. Just __advertising__ that they can be stored: Policy over Implementation. – bluevector Jun 07 '12 at 01:18
-
Can you elaborate a bit more on storeuser() – KiloJKilo Jun 07 '12 at 01:21
-
If the same same RL-person is both a mobile- and a web-user should he/her be to different "Users"? If the answer is no, I doubt you want "Users" to be an abstract class ... – esej Jun 07 '12 at 01:35
2 Answers
1
Basically everything is right except that User
should just be a normal class (not abstract).
Remember that abstract
classes should be used when you want your class to define a certain set of shared behaviors, while forcing its subclasses to provide others. This isn't the case in your situation. Rather, your subclasses simply provide additional behavior to the User
class.

Alex Lockwood
- 83,063
- 39
- 206
- 250
0
Some people consider making every class abstract which has subclasses and every class final which is a leaf good design practice. If you would want to adhere to that principle and still want to instanciate users you would need another subclass which is final.

Christian
- 13,285
- 2
- 32
- 49