Collaboration diagram
-
The collaboration diagram for
enterItem
is
-
This creates
as needed
- It does not create
- Post
- ProductCatalog
- ProductSpecification
Startup Use Case
- How does the system start up?
- It must initialise various objects that are not otherwise created
- It must establish associations between these objects
- It must start an initial processing action on the Controller
objects (e.g. POST)
Startup Use Case for Menu-driven Application
- Create ProductCatalog
- Create POST
- Let POST know about ProductCatalog
- Create Menu
- Let Menu know about POST
- Start Menu processing
Startup Use Case for Application Test
- Create ProductCatalog
- Create POST
- Let POST know about ProductCatalog
- Call methods on POST
- Check state of POST
Create ProductCatalog
- ProductCatalog is a persistent object, with state maintained
from one "run" of the application to another
- Let a Database Broker create all persistent objects such
as ProductCatalog
CatalogBroker
import java.io.*;
public class CatalogBroker {
public ProductCatalog getCatalog() throws Exception {
ProductCatalog catalog = null;
FileInputStream fileIn = new FileInputStream("catFile");
ObjectInputStream objIn = new ObjectInputStream(fileIn);
Object obj = objIn.readObject();
objIn.close();
catalog = (ProductCatalog) obj;
return catalog;
}
/**
* @pre catalog != null
*/
public void commit(ProductCatalog catalog) throws Exception {
FileOutputStream fileOut = new FileOutputStream("catFile");
ObjectOutputStream objOut = new ObjectOutputStream(fileOut);
objOut.writeObject(catalog);
objOut.close();
}
}
Linking the ProductCatalog and POST
Starting the Application (Java)
From the Application
's main()
method
public class Application {
public static void main(String[] argv) {
CatalogBroker broker = new CatalogBroker();
ProductCatalog catalog = null;
try {
catalog = broker.getCatalog();
} catch(Exception e) {
System.out.println("Can't get catalog " +
e.toString());
System.exit(1);
}
Post post = new Post(catalog);
....
}
}
Starting the Application (Jacl)
set catBroker [java::new CatalogBroker]
java::try {
set catalog [$catBroker getCatalog]
} catch {TclException err} {
puts "Can't get Product Catalog"
puts $err
}
set post [java::new Post $catalog]
...
Creating an Initial ProductCatalog (Java)
public MakeCatalog {
static public void main(String[] argv) {
ProductCatalog catalog = new ProductCatalog();
catalog.add(123, "descr1");
catalog.add(234, "descr2");
catalog.add(345, "descr3");
CatalogBroker catBroker = new CatalogBroker();
try {
catBroker.commit(catalog);
} catch(Exception e) {
System.out.println("Couldn't save Product Catalog" +
e.toString());
}
}
}
Creating an Initial ProductCatalog (Jacl)
package require java
set catalog [java::new ProductCatalog]
$catalog add 123 descr1
$catalog add 234 descr2
$catalog add 345 desrc3
set catBroker [java::new CatalogBroker]
java::try {
$catBroker commit $catalog
} catch {TclException err} {
puts "can't save Product Catalog"
puts $err
}
Miscellaneous Jacl Comments
- The contract for
Sale.makeLineItem(spec, qty)
includes
getLastItem().getSpecification().equals(spec)
- This says that the specification object in the new LineItem is the
same as the original
- Due to the way variables are handled in Jacl, you need to make
the specification object global
set spec1 [java::new ProductSpecification 123 spec1]
test test-1 {makeLineItem boundary case, 1 item} {
set sale [java::new Sale]
$sale makeLineItem $spec1 3
set lastItem [$sale getLastItem]
set spec [$lastItem getSpecification]
} $spec1
- The contract for
Sale.getTotal()
includes a summation
total is the sum of the subtotals for all the
SalesLineItems
- This cannot be specified as an iContract condition,
but it can be tested
Jan Newmarch (http://pandonia.canberra.edu.au)
jan@ise.canberra.edu.au
Last modified: Thu Sep 7 13:59:15 EST 2000
Copyright ©Jan Newmarch