Rule #2: No clone can make clone of himself. (This rule begins
to work AFTER one clone make a copy of himself for the first time.)
- Person
- I am a Person. I know my name. Also, I can set my name.
I know if I am male or female by checking which subclass I belong to.
I can ask one to marry me if I want. And, as a human being, I can say
any sentence to another Person, or just say it.
- Man
- I am a Man. ("I'm the MAN!", Will Smith.) Besides everything
one can do as a Person, I know if I am married. I know who is my wife
if I am married, and I can marry one if I am not and she is not either. I can
make love with my wife, but I can not do it with other woman. But
if I am a Clone, (you know, a Clone is also a Man,) I won't do it
because of Rule #1.
- Doctor
- I am a Doctor in Gemini Institute. I know how many clones I have
made. I can make a clone for a man. They will have same wife, and same
name. But the index number will be appended to the clone's name. I can
also make a copy for a clone. But I will do it only once, because
I will find the clone of clone's acts like Rain Man. I will obey Rule #2.
And, due to the limited fund we have, I can not clone a woman now.
- Woman
- I am a Woman. Besides everything
one can do as a Person, I know if I am married. I know who is my husband
if I am married, and I can marry one if I am not and he is not either. I can
make love with THOSE WHOSE WIFE IS ME, instead of only my husband, because
I can not tell the difference between my husband and his clones.
- Clone
- I am a clone. I can be either a copy of a Man, or a Clone. So, I am
a Man. Besides, I know my clone index number.
OOD
- Person
- I am a Person. I have an instance variable name.
I can access this variable with methods name and
name:
I have a gender method, which is:
gender
self class printString = 'Woman'
ifTrue: [^'female']
ifFalse: [^'male']
(Strong should not appear in OOD. It is here just to help your coding.)
I can speak by method say: (in the format "[my name]:[my words]")
or speak to somebody using say: to: (in the format
"[my name]:[my words], [listener's name]").
I also have a method marry:, in which I will only say
"Will you marry me?" and do nothing else.
- Man
- I am a Man, which is a subclass of Person. I have an instance variable
wife. Yes, you are right, I have methods
wife and wife: too. I have a method
married with works by checking if my wife variable
is nil. When I want to marry someone, with marry: method, I
will first use my superclass's marry: to ask for it, and then
check if I am married, if that one is female, and if she is married. If
all satisfied, my wife will be her, and her husband
will be me.
I can make love with one, using method makeLoveWith:,
I will first check if she is my wife, then check if I am a Clone
(self class printString = 'Clone' ifTrue: ifFalse).
If I am a Clone, I can not do it for Rule #1. If I am not, I will
say "I love you." to my wife, and she will say that to me.
- Doctor
- I am a Doctor, which is a subclass of Person. I know how many clones
I have made by maintaining a cloneIndex instance variable.
When I am created, I will set it to 1. Also I have an instance variable
rule2 which was set to false at the beginning. Those two
setting will be done in the method init.
When I want to clone: someone, I will check if he is a Man.
I can not clone a Woman. If he is a Man, I will check if he is a Clone.
A Clone can be cloned if and only if no clone has been cloned before.
After one Clone is cloned, I will set rule2 to true.
But this won't affect the cloning of a Man who is not a Clone.
- Woman
- I am a Woman, a subclass of Person. I have an instance variable
husband. My methods are counterparts of the methods in
Man class. The only difference is when I want to makeLoveWith:,
I only check if his wife is me.
- Clone
- I am a Clone, which is a subclass of Man. I have an instance variable
index. Also, I have an actualName
variable. My name is my actual name followed by my index
.
OOP
Your job now!
Remember to set the Setting of VisualWork first.
After you have finished, you write:
|doug laura doug2 leeds doug3 doug4 tmp|
doug := Man new.
laura := Woman new.
doug name: 'Doug'.
laura name: 'Laura'.
doug marry: laura.
leeds := Doctor new init.
leeds name: 'Leeds'.
laura marry: leeds.
doug2 := leeds clone: doug.
doug3 := leeds clone: doug.
doug4 := leeds clone: doug2.
tmp := leeds clone: doug3.
doug makeLoveWith: laura.
doug2 makeLoveWith: laura.
doug3 makeLoveWith: laura.
doug4 makeLoveWith: laura.
laura makeLoveWith: doug3.
tmp := leeds clone: laura.
in Workspace and do it, you will be asked "tmp's
value is never used". You select proceed, and you should
see:
Doug: Will you marry me, Laura
Doug: I will take you as my wife,Laura
Laura: Will you marry me, Leeds
Laura: I am married already.
Doug 2: Who am I?
Doug 3: Who am I?
Doug 4: Who am I?
Leeds: No more clone,Doug 3
Doug: I love you, Laura
Laura: I love you too, Doug
Doug 2: I can"t because of rule #1.
Doug 3: I can"t because of rule #1.
Doug 4: I can"t because of rule #1.
Laura: I love you, Doug 3
Doug 3: I love you too, Laura
Leeds: We can only clone a man now, Laura.
if all what you did is correct.
Turning In
Same requirement as in Lab #2. Remember to quit your VisualWork before
you close your window management system.