The fact that habitat is described on those slides as a “property” of an animal suggests you would want a habitat object as a field in the animal class.
Lakshmanan Arun
http://devtoolzone.com
Lakshman Arun wrote:From the problem you describe, I think of LevelRole and AttendanceRole should be part of Student Class as attributes.
LevelRole can be extended by UG class and PG Class.
Similarly attentancelevel can be extended by FullTime class and PartTime class.
Note: if the behaviour doesnt change based on the levelrole/attendencerole then think about using simple ENUM
Have you tried that? What is going to happen when you have this sort of pseudocode?How are you going to tell from the field what the student's status is? Please show a brief implementation.Lakshman Arun wrote:. . . LevelRole can be extended by UG class and PG Class. . . .
Lakshmanan Arun
http://devtoolzone.com
Lyle Christine wrote:
Lakshman Arun wrote:From the problem you describe, I think of LevelRole and AttendanceRole should be part of Student Class as attributes.
LevelRole can be extended by UG class and PG Class.
Similarly attentancelevel can be extended by FullTime class and PartTime class.
Note: if the behaviour doesnt change based on the levelrole/attendencerole then think about using simple ENUM
Thanks for the reply Lakshman - if you take a look at the post above your reply, my confusion is how would set theLevelRole and AttendanceRole attributes. Is my setter method suggestion correct, and if so, what do I pass as the parameter in the setter method?
Lakshmanan Arun
http://devtoolzone.com
. . . and using something like Objects#requireNonNull().Lakshman Arun wrote:. . . mandatory attributes without setting that , Student Object is not complete.
So should be passed thru constructor
Lakshmanan Arun
http://devtoolzone.com
Good, but don't call UG and PG types; they are instances. Even if they have different implementations of a method.Lakshman Arun wrote:Can be added methods in enum LevelRole as abstract and in each type UG/PG override it. I got your point.
If you set the level in the constructor, you can be sure it will be set. As you will see from this discussion, also today, there are ways to avoid null being passed. If you have a method, there is no way you can “make” users call that method, so there is a risk of that field not being set and the object being in an inconsistent state. In fact, most users take it for granted that the object will be in a consistent state after the constructor completes and won't look for methods to be called afterwards.Lyle Christine wrote:. . . At first I thought I this would be incorporated into the constructor of the Student class, . . . have a setLevelRole() method in the Student class which you would have to call immediately after a Student object is created? . . .
* Problem:
- Two or more objects are required if the animal needs to play different
roles, like aquatic and land carnivore, which is not good OO design.
Lyle Christine wrote:and let's say my UnderGraduate class is this:
I know a slightly different version of that process.Junilu Lacar wrote:. . . Then I slowly refactor the code, move things around, change the design little by little, so that it eventually follows the known pattern.
. . . Then I slowly refactor the code, move things around, change the design little by little, until I realise it is following a pattern.
Campbell Ritchie wrote:I know a slightly different version of that process
. . . Then I slowly refactor the code, move things around, change the design little by little, until I realise it is following a pattern.
“The strongest of all warriors are these two — Time and Patience.” ― Leo Tolstoy, War and Peace
Lyle Christine wrote:Hi everyone, I've asked the following question on javaprogrammingforums.com - apologies if cross-forum posting is frowned upon, but no one there has replied.
I'm new to design patterns and currently trying to create a simple example of the following actor-role pattern (sometimes known as player-role pattern):
Hey Lyle, what tool or IDE are you using for modelling the UDM ?
You will always be treated with dignity. Now, strip naked, get on the probulator and hold this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|