You will extend the weasley model to include some security concerns
and make it ready for use to drive a Weasley Clock.
- Continue working, if you like, on the portion of the Weasley clock
that is due for your midterm, as described in
You can work with the same or with different people. Your work is contained
in your personal repo and should be committed there.
- The extra functionality described in this lab is due (not when your
midterm is due, but) as shown on the
The design you developed for Studio W was
driven by the Main class in terms of the methods you needed.
You were mostly able to determine the methods' functionality based on
their names and on the code in Main.
However, while the user story seemed OK at first, most of you discovered
there were certain areas of functionality that were unmentioned
in the story. These dark corners
(cue the spooky music) of the specification
included at least the following:
- Where is a Person if no location has yet been
associated with that Person?
- If a Location is dropped, what happens to
who was mapped to that Location? (What would getLocation(p) return for such a Person p)?
- If all people mapped to a Location are dropped, what happens
to the Location? Is it still in the set of
- What happens if I do setLocation(pers,loc), but have not
previously added Person per or Location loc?
- The most straightforward implementation of the specification will
probably lead to a ConcurrentModificationException problem,
even though your code has no concurrency. This happens because
while Main is iterating over a set (say, the set
returned by getPeople()), a Person is removed from
that set. Think about how to fix this problem and ask for help if you
need it. If you fix the problem by changing Main, then some
other code that uses your Weasley object may break down the
road, so try to fix it in Weasley.
Unit-testing problem resolution
There is a unit test WeasleyTest you will find by updating your
personal repo. Run it.
The unit tests may emit messages that are coded by a problem letter. The
explanations are below:
- The .equals(Object) method must be defined for your objects,
especially Person and Location. These should be based
on the equal-ness of their contains Strings. These methods can
be automatically generated by eclipse.
- The .hashCode() method must be defined for your objects,
especially Person and Location. These must honor the
contact that if two objects .equal each other, then their
hashCode()s must be the same.
- What happens if a person is mapped to place never before identified to
the model? Is that location now in its known set of locations?
- Objects of different types should never equal each other. If you autogenerate
the .equals(Object) method the code that is emitted will handle this
- Unless you have good reason (and if so, change the test and explain this
to a TA), a Person should have some location, even if that location
is "Lost" or "Unknown". Recall the Weasley clock in the books and movies always
had some notion of where its people were located.
- What about a person who has never before been identified to the model?
Unless you have good reason (explain yourself), then such people also might not
map to null. This test is to make you think about this
The model as it stands now should reveal the Location of
any Person no matter who is asking for the information.
For the time you have left
in lab, consider how you might evolve the model to take account of who is asking.
You might consider the following, keeping in mind that eventually a request
to the model can contain the screenname of the requestor, which suffices to authenticate
the sender of the request.
- You may not want certain people to know your location. For example, you
may not want parents to know you're out partying, or robbers to know that you're
out of town.
- You may not want everybody to have the capability of setting the location
of a Person.
- Perhaps the model's design is flawed, in the sense that it accounts for
more than one Person. Would a better design have each model
- Or perhaps the mode is OK and you need some front-end to deal with the
Last modified 08:59:25 CDT 03 June 2010
by Ron K. Cytron