Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

class diagram of MVC

 
Suman Dass
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have one abstract class Employee with
attributes - (Name, Address)
method - Hire().
I have two child classes, HourlyEmployee with
attribute - (Rate)
and Salaried Employee with
attribute - (Salary)
So when I draw the class diagram, I have the two child classes pointing to the parent.
Now, during implementation, we have layered the classes, i.e. we no more have the parent class. Instead we have
1. HourlyEmployee class containing only the attribute "Rate" and
2. Hourly EmployeeHandler class containing the method "Hire"
and
3. SalariedEmployee class containing only the attribute "Salary" and
4. SalariedEmployeeHandler class containing the method "Hire"
My question is how we can show relationships in such situations. Do we revert to the logical model or try to draw relationships on the existing relationship?
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The model and code should always be synched. If you dropped the abstract super class from the code, drop it from the model also.
If you ask me, I would've kept the abstract super class. Is there any particular reason for dropping it?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What was your motivation for the handler classes? What is the connection to the MVC pattern?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Employees like this are found in some examples in Robert Martin's Agile Software Development. He wound up with a single employee class with a variety of payment strategy objects. If a person is promoted from hourly to salary, can an employee object change class? Not in Java. But it can replace it's hourly payment strategy with a salary payment strategy.
Look for Gang of Four Strategy pattern or maybe State pattern. Both delegate behavior to other objects when behavior can change over time.
[ August 27, 2003: Message edited by: Stan James ]
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now that Stan mentioned it, I think Fowler also used an Employee class hierarchy as an example in Refactoring.
 
Fintan Conway
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stan James:
He wound up with a single employee class with a variety of payment strategy objects. If a person is promoted from hourly to salary, can an employee object change class? Not in Java. But it can replace it's hourly payment strategy with a salary payment strategy.

The Classifier Design Pattern would also be appropriate in this case.
Regards,
Fintan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic