TheInsider
Programmer
Hi,
I posted this in the UML forum but then found this forum, which is probably a better place to ask this. I'm new to good class design . Anyway, I'm working on a Class diagram that has me puzzled. To make this easy, I'll use an analogy rather than describe my project in great detail. Let's say I have a Use Case diagram, and on it, I have two actors:
So, essentially a tenant lives in a building and so does a landlord.
Now, let's say that Tenant can "Do X to Building" and "Do Y to Building", and Landlord can "Do Z to Building" because Landlord has extra special privileges.
Here's where I'm having a problem. Assuming that I have a Tenant class and a Building class as follows:
Is there really a need for a Landlord class? Assume for a moment that Tenant.phoneNumber is a unique key. Wouldn't it make sense to simply check who is calling Building.doZtoBuilding() within the method doZtoBuilding() and if that Tenant object doesn't have the same phoneNumber as is stored in Building.landLordPhoneNumber then don't allow the method to execute any further?
Since the "do..." methods are acting upon building, it doesn't make sense to make them methods of Tenant or Landlord classes. And, if the "do..." methods aren't methods of the Tenant or Landlord classes, then the Tenant and Landlord classes would essentially have the same properties and methods. And, since a Landlord is also a Tenant, having a Landlord class would be redundant using the above design.
I hope that made some sense. I'm trying to figure out if this is a bad design, and if there is a need for a Landlord class.
Thanks
I posted this in the UML forum but then found this forum, which is probably a better place to ask this. I'm new to good class design . Anyway, I'm working on a Class diagram that has me puzzled. To make this easy, I'll use an analogy rather than describe my project in great detail. Let's say I have a Use Case diagram, and on it, I have two actors:
Code:
Tenant
/\
|
<<inherits>>
|
Landlord
Now, let's say that Tenant can "Do X to Building" and "Do Y to Building", and Landlord can "Do Z to Building" because Landlord has extra special privileges.
Here's where I'm having a problem. Assuming that I have a Tenant class and a Building class as follows:
Code:
================
Tenant
================
-phoneNumber
================
+getPhoneNumber()
+setPhoneNumber()
================
| 0..*
|
| /\
|has
|
| 1
================
Building
================
-address
-landLordPhoneNumber
================
+doXtoBulding()
+doYtoBulding()
+doZtoBulding()
================
Since the "do..." methods are acting upon building, it doesn't make sense to make them methods of Tenant or Landlord classes. And, if the "do..." methods aren't methods of the Tenant or Landlord classes, then the Tenant and Landlord classes would essentially have the same properties and methods. And, since a Landlord is also a Tenant, having a Landlord class would be redundant using the above design.
I hope that made some sense. I'm trying to figure out if this is a bad design, and if there is a need for a Landlord class.
Thanks