Concepts: class, object, package, attribute, association, aggregation, composition, generalization, substitution principle, stereotypes (entity, event, role, description), value versus reference objects, A-box, T-box.Patterns: Types as Objects, Actor-Role Problems:
1. Translate a textual domain description into a class and/or object diagram.
Translate into a class diagram:
For each product type, and inventory contains 0 or more items of that type. Items can be added to or removed from the inventory. Each time an item is added or removed from the inventory a transaction record is created and placed on the inventory's statement. An item has a price, a description, a product code, and a flag indicating if it is being held for a customer.
A customer owns a cart that contains items. Items can be added to or removed from the cart. Carts also have a checkOut method. Adding an item to the cart puts the item on hold. Checking out removes the items from the inventory and returns the invoice.
Using a sequence diagram, describe a typical shopping scenario in which a customer adds and removes items from his cart and then checks out.
Bill is a customer at Euphrates.com. He adds two books and a CD to his cart. Draw an object diagram showing this situation.
Concepts: these include the concepts from domain modeling, but with different interpretations (can you explain?). In addition: interfaces, methods, reflection, inheritance, subtype polymorphism, parametric polymorphism, overloading, overriding, subsumption (same as substitution), dynamic dispatch, data-driven versus control-driven programming, delegation.
Principles: Open-closed, Modularity, Abstraction
Metrics: responsibility, stability, LCOM1, LCOM2, couplingDegree
Patterns: Adapter, Bridge, Strategy, Publisher-Subscriber
class AAA {
int a, b, c,
d, e;
int m1() {
return a + b + c; }
int m2() {
return b + c + d; }
int m3() {
return c + d + e; }
int m4() {
return a + d + e; }
}
a. Draw a method coupling graph (MCG(C)) and use it to
compute LCOM1(C)
b. Draw a method-attribute graph for C (MAG(C)) and use it to compute LCOM2(C)
class A {
B b = new
B();
int m1() {
return b.f1(); }
int m2() {
return 0; }
int m3() {
return b.f2(); }
int m4() {
return b.f1() + b.f2(); }
}
class B {
int f1() {
return 1; }
int f2() {
return 2; }
int f3() {
return 3; }
int f4() {
return 4; }
}
Assume Runner, Footballer, and Cricketer are some subclasses of Athlete. A team contains many athletes, but all of the same class. We can add and remove players from a team. Implement Team as a generic class.
Complete the following declaration:
public class UnitTest
{
List<Integer> inputs = new ArrayList<Integer>();
List<Integer> outputs = new ArrayList<Integer>();
String methName,
className;
boolean
test() { ??? }
}
The test method feeds each input in the inputs list to the method in class className that is named methName and takes a single input of type Integer.class and returns an output of type Integer.class. Test compares each output with the corresponding entry in the outputs list. If there are no differences, true is returned, otherwise false is returned.
What code with an intelligent Java code generator generate from the following class diagram:
Assume your code generator automatically generates management methods such as getters and setters for fields, and collection management methods collections. It should also generate implementations of inherited abstract methods.
You should be familiar with the following patterns:
Actor-Role
Types as
Composite
Strategy
Publisher-Subscriber
Model-View-Controller
Abstract Factory
Proxy/Decorator
Master-Slave
This includes familiarity with the participant names used in class, the pattern structure and dynamics, the problems solved by the pattern, and common examples where the pattern is used.
1. The following design of a CAD/CAM system uses the Model-View-Controller pattern refined by the Publisher-Subscriber pattern and the (smart) Command Processor pattern:
Use your knowledge of the dynamic behavior of these patterns to complete the following sequence diagram:
2. A maze contains any number of chambers. A chamber has 1 to 4 doors that connect it to other chambers. A chamber has a description, an entry penalty, and may contain a treasure.
Company X provides a class called Dungeon and company Y provides a class called Lab. Both of these classes have the functionality required by Chamber class, but the method names are slightly different:
Draw a class diagram showing how you would combine the Bridge, Adapter, and Factory Method parameters so that a game designer could use the maze framework to create a complex maze consisting of dungeons or labs.
3. Draw UML class diagrams showing how you would apply the given pattern to the given problem.
Problem: A design analyzer measures the quality of the design of a package. Of course there are many ways to do this.
Pattern: Strategy.
4. Problem: In an asynchronous method invocation a client object places a request in the mailbox of a provider object asking it to execute one of its methods. Now the client can do something else without having to wait for a return value. If and when the provider executes the desired method, it places the result in the client's mailbox. But how will the client know when the result has arrived?
Pattern: Publisher-Subscriber
5. An instance of the BaseballPlayer class has a play() method. The behavior of this method depends on the position the player plays. On defense, a player can play any one of the nine field positions. On offense a player can be a batter or a runner. Sketch an implementation of the BaseballPlayer class. Hint: use the Strategy Pattern.
In each case say what's wrong with the design, then draw a class diagram showing how you could improve the design. If you employ any design patterns, say what they are.
1.
2.
Stateless vs. Stateful protocol
What are the major distributed architectures and how are they different?
How is the decorator pattern used with streams in Java?
How is the Publisher-Subscriber pattern used to handle button clicks in Java?
How is the Model-View-Controller pattern used to implement GUI controls in Java?
Be able to write simple Java classes that either extend Thread or implement Runnable.
Know how to create and run slave threads from a master thread.
Know how a thread can lock an object to prevent synchronization problems.
How is the Master-Slave pattern used?
Know how the Proxy Pattern is used to add features to a server. Be able to draw sequence and object diagrams. Be able to implement a chain of proxies in Java.
Assume the following interface is defined:
public interface IServer
{
void post(String s);
String get();
}
Assume the following server is defined:
public class Server implements IServer {
private static List<String> messageBoard =
new ArrayList<String>();
public void post(String s) {
synchronized (messageBoard)
{
messageBoard.add(s);
}
}
public String get() {
String result = "";
synchronized(messageBoard)
{
for(String s: messageBoard)
{
result = result + '\n' + s;
}
}
return result;
}
}
Implement a proxy for this interface (Proxy.java)
Implement a cache proxy (CacheProxy.java)
Here's a client:
public class Client extends Thread {
private IServer
myServer;
public Client(IServer
s) {
myServer =
s;
}
public void run() {
try {
myServer.post("message1");
Thread.sleep(1000);
myServer.post("message2");
Thread.sleep(1000);
myServer.post("message3");
System.out.println(myServer.get());
} catch(Exception e) {
}
}
Write a main that creates 2 clients that each uses a cache proxy. Start them, then wait for them to end. (See Client.java)
What would happen if messageBoard is not static?
What would happen if access was not synchronized?
Assume access is not synchronized. Create a synchronization proxy.
Create a proxy that prevents dirty words from being posted to the message board.
Create a ReaderWriter thread. These threads should read lines from an input file (use a buffered reader) and write to a single output file (use a print writer). Create a file manager that creates the output file, a bunch of threads, and then launches them.
(See FileManager.java)
Try taking the sample final posted in WebCT. This will give you an idea of some other types of questions I am contemplating.