- Tutorial 9 continues on the work of Tutorial 8 and Exercise in the Coursebook.
- CHECK SUBMISSION BOX, TUTORIAL 9, CLASS A05 and B05 for source code.
- A OOP head space in java, usually, have the following contents:
/**
* @overview
* @attributes
* (name) (class wrapper) (data type of class wrapper in the PL)
* @object
* @abstract_properties
*/- State space specification:
public class ClassName {
@DomainConstraint()
priavte (datatype) name ();
....
}- The implementation (ah, it's what we talk about today).
- Last week, we've write the headspace and state space specification. It's method time this week.
- An (unifinish) code of the program:
/**
(state space)
/*-
Consider if we want to construct a Banh Chung object (WHYYYYY...?) (image)
-
So, in order to construct something, in our case, Banh Chung, it need to take in ingredients (state space specs), and return an instance.
-
A notable thing: This instance will have the same name as in our class.
-
An example (using the Person class in last week problem):
/**
* if a method is NOT optional -> put something inside the param.
* and also we need to add the description before.
* ----------------------(remove this line and anything above it)
* @effects <pre>
* if id, name is valid
* initialize this as <id, name>
* else
* throws NotPossibleExeception
* </pre>
*/
public Person (@int id, String name) (@AttrRef("id") int id, @AttrRef )
{
if
this.id = id; // to make sure that this is a value that the user input in
this.name = name;
}
// it returns nothing; but instead of void, it'll return that Object.- Usually start with get.
- The principle behind it is this: for each
/**
* since id is int, the get method data type is THE SAME as the type of data.
* ------ (ignore this line) ---------
* @effects <pre>
* return this.id
* </pre>
@DOpt (type= OptType.observer)
@AttrRef("id")
public int getId() {
return this.id;
}- For each attribute which is mutable, creater a Setter (Mutator)
- We use the class Person here (see Textbook for the original
/**
* @modifies this.name
* @effects <pre>
* if newName is valid
* set this.name = newName\
* return true
* else
* return false
* </pre>
public boolean setName (string newName)
{
this.name = newName;
}- The idea is this, for each attribute, we will have a validator.
/**
* @effects <pre>
* if id is valid
* return true (hence the boolean)
* else
* return false
* </pre>
private boolean validateID(){
// Since we've already tested most of the previous conditions
// We will test something that is unique.
// int data has a min or max. So, we will tets that.
// Also we will modify the Constructor above:
}- Some note about String (and null)
- In some case
- Using the Banh Chung example: This is to MAKE SURE WE DON'T GET FOOD POSIONING.
## Some notes on Assignment 2:
- ```Set``` and ```PCProg``` are given.







