software development csu 670 fall 2007 karl lieberherr

35
Software Development CSU 670 Fall 2007 Karl Lieberherr

Post on 20-Dec-2015

216 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Software Development CSU 670 Fall 2007 Karl Lieberherr

Software DevelopmentCSU 670 Fall 2007

Karl Lieberherr

Page 2: Software Development CSU 670 Fall 2007 Karl Lieberherr

Textbook

• Booch: OOAD(3)– Concepts

• partially a review from OOD but much new material, e.g. – Law of Demeter (pages 116, 117)

– Method• partially a review from OOD but much new material, e.g.,

– software development lifecycle

– project management

– Applications• useful examples

Page 3: Software Development CSU 670 Fall 2007 Karl Lieberherr

Project: Algorithmic Trading of Derivatives

• Derivatives are financial instruments whose value derives from the value of assets underlying them"

• Examples of the financial instruments used in derivatives transactions, which reference these underlying assets include: options …

• Options are financial instruments that convey the right, but not the obligation, to engage in a future transaction on some underlying security.

Page 4: Software Development CSU 670 Fall 2007 Karl Lieberherr

Website

• for selling and buying derivatives• derivatives can be created on the fly• Derivative:

– Kind: G– creator name (has to provide raw material of kind G,

has to pay for finished product)• price offered

– buyer name (has to work to produce finished product)• price paid

– outcome• raw material provided• price to be paid by creator

Page 5: Software Development CSU 670 Fall 2007 Karl Lieberherr

• possibility for re-selling a derivative that was bought

• is this different than offering the derivative with a higher price

• are prices public?

Page 6: Software Development CSU 670 Fall 2007 Karl Lieberherr

Special kinds of derivatives

• Derivatives are often used to control risks: weather, foreign currency fluctuations, interest rates.

• Evergreen derivatives don’t control risks that depend on unknown time-dependent factors.

• They depend on G = set of relations. This is a time-independent known object.

Page 7: Software Development CSU 670 Fall 2007 Karl Lieberherr

Abstract problem: Pricing of derivative

• Pricing of following derivative D(G): option to get for free one batch of raw material of type G (details of batch unknown) and the option to sell the finished product made of the raw material within one day of receipt of the raw material at a price proportional to the quality of the finished product.

• all prices are in [0,1] (million dollars).

Page 8: Software Development CSU 670 Fall 2007 Karl Lieberherr

Concrete Problem

• batch of raw material of type G– G-formula F

• finished product– assignment J for G-formula F plus F

• quality of finished product– satisfaction ratio of assignment J for F

Page 9: Software Development CSU 670 Fall 2007 Karl Lieberherr

Questions

• How much is D(G) worth for a given G?

Page 10: Software Development CSU 670 Fall 2007 Karl Lieberherr

CNF: a simple language

Program = Expression.Expression : LetExp | CNF.LetExp = <assign> Literal <body> Expression. CNF = <clauses> List(Clause).Clause = <weight> Weight <body> Body.Body : Literals | Sat | Unsat.Sat = “sat”.Unsat = “unsat”.Literals = <literals> List(Literal).Literal : Pos | Neg common Variable.Variable = <v> Ident.Pos = .Neg = .List(S) ~{S}.

Page 11: Software Development CSU 670 Fall 2007 Karl Lieberherr

Values

• expressed values– possible values of expressions

• CNF (results of reductions)

• denoted values– values bound to variables

• Literal (assignment)

Page 12: Software Development CSU 670 Fall 2007 Karl Lieberherr

Environments

• store values associated with each variable

Page 13: Software Development CSU 670 Fall 2007 Karl Lieberherr

Let expression

(value-of (LetExp lit body) s) =

(value-of body [lit] s)

Page 14: Software Development CSU 670 Fall 2007 Karl Lieberherr

CNF

(value-of (CNF clauses sat unsat) [l] s) =

(CNF clauses1 sat1 unsat1)

(value-of (Clause weight literals)[l] s) =

(Clause weight1 body)

Page 15: Software Development CSU 670 Fall 2007 Karl Lieberherr

Exercise 1.17

• (down lst) wraps parentheses around each top-level element of lst.

• solution: – from list:List to r:topLevel(list)

• replace r by (list r)

Page 16: Software Development CSU 670 Fall 2007 Karl Lieberherr

Exercise 1.27

• (flatten slist)

• solution:

• from Root to p:Primitive collect p into list

• notice generalization: flatten other structures than lists

Page 17: Software Development CSU 670 Fall 2007 Karl Lieberherr

Help with project 2

• Understanding code: find the data abstractions

• Data abstraction: separate interface from implementation

Page 18: Software Development CSU 670 Fall 2007 Karl Lieberherr

Interface for a class dictionary

• Constructors: LetExp(Literal,Expression)– Clause_PList(Nonempty_Clause_PList)

• Accessors: LetExp: – Literal get_assignment(), – Expression get_body()

• Parser: static LetExp.parse()• Printer (needs a bit of code because

PrintVisitor is provided) • similar for other visitors

Page 19: Software Development CSU 670 Fall 2007 Karl Lieberherr

For phases 3 and 4: List Structure

• List(X)

X_List NonEmpty_X_Listfirst

next

X

it

Page 20: Software Development CSU 670 Fall 2007 Karl Lieberherr

Iterating through a DemeterJ list

• Have an X_List xlist;

java.util.Enumeration en = xlist.elements();

while (en.hasMoreElements()) {

if (e.equals((X) en.nextElement()))

{ found = true; }

found = false;

}

Enumeration Interfaceboolean hasMoreElements();Object nextElement();

Page 21: Software Development CSU 670 Fall 2007 Karl Lieberherr

Iterating through a DemeterJ list:

in class X_Listpublic java.util.Enumeration elements() {

return new X_List(first);

}

public Object nextElement() {

X car = first.get_it();

first = first.get_next(); return (Object) car;

}

Page 22: Software Development CSU 670 Fall 2007 Karl Lieberherr

Iterating through a DemeterJ list:

in class X_Listpublic boolean hasMoreElements()

{ return (first != null); }

Page 23: Software Development CSU 670 Fall 2007 Karl Lieberherr

Enumeration interface is old fashioned

• Use Iterator interface instead– boolean hasNext();– Object next();– void remove(); (optional operation)

• Compare to

Enumeration Interfaceboolean hasMoreElements();Object nextElement();

Page 24: Software Development CSU 670 Fall 2007 Karl Lieberherr

Enumeration interface is old fashioned

• ListIterator is a subinterface of Iterator– boolean hasNext();– Object next();– void remove(); (optional operation)– add, hasPrevious, previousIndex, nextIndex,

previous, set

Page 25: Software Development CSU 670 Fall 2007 Karl Lieberherr

Java documentation

• The functionality of the Enumeration interface is duplicated by the Iterator interface. … shorter method names ... New implementations should consider using Iterator in preference to Enumeration.

Page 26: Software Development CSU 670 Fall 2007 Karl Lieberherr

Traversal with a ListIterator

void traverse_maxSize(IntegerRef m){

for (ListIterator i=this.listIterator(); i.hasNext();)

{

DirectoryEntry de =

(DirectoryEntry) i.next();

de.traverse_maxSize(m);

}

Page 27: Software Development CSU 670 Fall 2007 Karl Lieberherr

How can you get an Iterator?

• Interface Collection:– Iterator iterator();

• Example: – class Vector implements interface List– interface List extends interface Collection– Therefore: Use the Iterator interface to go

through a vector

Page 28: Software Development CSU 670 Fall 2007 Karl Lieberherr

Context switch: Keep it simple with XML

Page 29: Software Development CSU 670 Fall 2007 Karl Lieberherr

XML

• Elements have Content• Elements can have different content types.• An XML element is everything from (including)

the element's start tag to (including) the element's end tag.

• An element can have element content, mixed content, simple content, or empty content. An element can also have attributes.

• We use only: element content and simple content.

Page 30: Software Development CSU 670 Fall 2007 Karl Lieberherr

Others, including the official XML authors

• Are for simplification.

Page 31: Software Development CSU 670 Fall 2007 Karl Lieberherr

From w3schools

• An expanded date element is used in the third: (THIS IS MY FAVORITE):

<note> <date> <day>12</day> <month>11</month> <year>2002</year> </date> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend! </body> </note>

Page 32: Software Development CSU 670 Fall 2007 Karl Lieberherr

From the w3schools website• Avoid using attributes? • Should you avoid using attributes? • Some of the problems with using attributes are: • attributes cannot contain multiple values (child elements can) • attributes are not easily expandable (for future changes) • attributes cannot describe structures (child elements can) • attributes are more difficult to manipulate by program code • attribute values are not easy to test against a Document Type

Definition (DTD) - which is used to define the legal elements of an XML document

• If you use attributes as containers for data, you end up with documents that are difficult to read and maintain. Try to use elements to describe data.

Page 33: Software Development CSU 670 Fall 2007 Karl Lieberherr

Don't end up like this (this is not how XML should be used):

<note day="12" month="11" year="2002" to="Tove" from="Jani" heading="Reminder" body="Don't forget me this weekend!"> </note>

Page 34: Software Development CSU 670 Fall 2007 Karl Lieberherr

From the official XML tutorialhttp://www.w3schools.com/xml/xml

_attributes.asp

• There are no rules about when to use attributes, and when to use child elements. My experience is that attributes are handy in HTML, but in XML you should try to avoid them. Use child elements if the information feels like data.

Page 35: Software Development CSU 670 Fall 2007 Karl Lieberherr

Based on the w3schools recommendation

• We decide to use only a subset of XML• We use elements and no attributes.• The elements either have element content

or simple content.• The simple content is either an Ident, a

String or a Text or any of the primitive types of Java (int, float, etc.) and their corresponding wrapper classes (Integer, Float, etc.)