When creating software, one very important skill to have is being able to plan what you will do. In this problem set, and future ones, we will give you a UML diagram so that you can have guidance on how to create your program. UML diagrams are a collection of classes and their corresponding properties and methods. This will give you an overall picture of what you’re trying to achieve. Let’s take a look at the UML for a previous year’s problem set and dissect parts of it.
There seems to be a lot going on here, so we will take it piece by piece. Let’s stat with the class called Listing:
This class is in seems to have a lot of connections to it, so it must be very important. In real life, a listing can be anything that is up for sale on a website. In this case, the website allows for people to bid how much they are willing to pay above the price. The highest bidder gets to buy the item. How would we write this class with code?
public class Listing { private String title; private boolean active; private User author; private int price; private List<Bid> bids; private String id; public Listing() { } }
This class has some properties, an empty constructor and we should probably add some getters and setters afterward. Notice that all of the properties are private since our UML diagram shows that they should (by using the minus sign). A plus sign would mean that it should be public.
Now we how a part that is a bit tricky. Remember that these classes are not the objects themselves, they are just blueprints of what the objects might be, once we construct them.
Part of our diagram shows the picture above. You’ll notice that a Listing can have a List of Bid objects. This means that we would first have to construct the bid and we would then have to add it to the List. One possible way to do this would be:
Bid currentBid = new Bid(); bids.add(currentBid);
Again, we must construct the bid and then we can add it to the List of all the other Bid objects.
What do the does the black diamond shape mean and the 1, 0..*?
A black diamond means that Listing will hold a collection of Objects of type Bid. The 1 means that one Listing can hold 0 or infinite number of Bid objects (0..*).