pkg core Room - yshehab/SchoolRoomBooking GitHub Wiki

Room Class

Overview

A room models a room in a particular school. The only thing unique for any given room in any given school is its name. However different schools may use the same name for a room.

Room is mutable so a defensive copy should be considered if a room instance is passed outside the core system.

Package

Core

Constructor

public Room(School school, String name)

    Pre-condition: name is not already the name for a room in school

    Post-condition: a new room instance is initialized with the supplied arguments.

public Room(Room room)    Copy constructor

    Post-condition: a copy of the room instance is initialized.

Static Members

None

Static Methods

None

Attributes

private String name

private int capacity    default is 20

private Roomtype roomtype default is RoomType.CLASSROOM

private School school

Links

Collection<Asset> assets    References a collection of all linked Asset objects. Default is an empty collection.

Protocol

public String toString()

    Post condition: returns a string representation of the receiver.

public boolean equals(Object room)

    Post condition: returns true if room is a Room object with the same state (school, name) as the receiver otherwise false.

public int hashCode()

    Post condition: a hash code of the receiver, consistent with equals.

public School getSchool()

    Post condition: returns the school attribute.

___public RoomType getType() ___

    Postcondition: returns RoomType.

___public void setType(RoomType type) ___

    Postcondition: sets the receiver_s roomtype attribute to type.

___public String getName() ___

    Postcondition: returns name.

___public void setName(String name) ___

    Postcondition: sets the receiver_s name attribute to name.

___public boolean hasAsset(Asset asset) ___

    Postcondition: returns true if the receiver has asset in assets otherwise false.

___public void addAsset(Asset asset) ___

    Postcondition: Adds the asset to assets unless it is already there.

___public void removeAsset(Asset asset) ___

    Postcondition: removes the asset from assets if it is there.

Examples

Discussion

I (neo) am going to suggest that we adopt a [http://javarevisited.blogspot.co.uk/2012/06/builder-design-pattern-in-java-example.html builder pattern] here to allow the addRoomToSchool use case to customize the new Room instance they want to create. The getters/setters and the copy constructor are not needed with the use cases that we have at the moment; should we remove them? I vote yes.

This is Ben_s take. I_ll ask some questions...

Constructor

___Room(String aName, Collection<Assets> assets, int capacity, Roomtype roomtype) ___

Postcondition: initialises a new Room object with the given attribute values.

I like this constructor but it doesn_t contain School. Also all these things can be changed, a classroom can be turned into media-studies suite, with a different capacity and different assets. And then it might be called something else. However that is not in the use cases and I like this to be done using the builder above. -- neo

Protocol

public collection <Booking> getBookings()

Post condition: returns a collection of Booking objects for the current day and the future which are linked to the receiver

I think that it would be better if LettingCoord took care of bookings. Why should a room know about who has booked it? However, this means I need to ask another set of questions which I_ll try to answer elsewhere. -- neo

⚠️ **GitHub.com Fallback** ⚠️