Patterns Discussion

Make a web page/area for the answers to these pattern questions.
After each class discussion, please answer these questions
about the patterns indicated.

Patterns covered so far in class:

Singleton

Factory, Abstract Factory

Composite, Bridge, Adapter

Flyweight, Decorator, Chain

Proxy

template method, memento, strategy, observer

command

Homework Milestones

A13(due 04/28/15 Tues. 4:00 pm, exam block) (via webpage)(team work)

Voting System Design: Final Materials and Presentation

Here are the requirements for the
online voting system.
You are producing a design for this system, using OO design patterns.
Prepare your materials on a web page (or several) and add the link to
your class webspace by the due date (which is the date of the
in-class presentation).
As with the other team work, each team will produce a joint product, but each
team member will link to that product separately in his/her personal class
web space.

You will present your design and give the rationale for it in class in
our exam slot, which is 4pm Tuesday April 28.
We will have 3 hours to do 9 team presentations, so prepare
for a 15 minute talk.
Please practice yours and time it so you know
it fits the alloted time.

The design should be explained as a collection of class/object
diagrams (as the design patterns are expressed in), with interfaces
defined at a top level (important methods and fields, but not necessarily
full details). If you want to or need to, you can use the other
diagrams from you text, such as sequence and timing diagrams.
Show where the patterns involved are, list them and explain what
part of the system functionality they are providing.
Give your rational... why did you choose certain patterns and structures,
and reject others?
Be prepared to explain your design decisions.

Prepare an in-class presentation... powerpoint, web pages, whatever is fine
for the presentation materials. No matter what form you use, please put the
presentation materials in your submitted web information.

A12(due 4/17/13 Fri 11:00pm) (via web page) (team work)

Do this assignment as a project team.

Each member of the team will submit the solution via their individual class
webspace, but the work will be jointly done by pair programming.
Put your source code files on the web so I can look at them with a browser.

ALTERATION/EXTENSION for STRATEGY
Take the code you wrote for the Networked Observer exercise
and alter is slightly... really, augment it.
Add to the application some code that follows the strategy pattern.
Create a parent class that all observers will use for the printing/reporting
strategy. Subclass it twice to make these two specific print strategies.
Print strategy 1:
When the observer decides it should report the state of
the subject, it will make a sort of a bar chart. Take the number that
the subject returns (lets say it's 56). Divide that by 10 (integer division).
Then print that many "*" characters along one line with the number at the end.
For the 56 example it will look like this:
*****56
56 div 10 is 5, so 5 "*" and then 56.
Print strategy 2:
When an observer decides it should report the state of the subject
it will do something kind of logarithmic. Here are examples:
for 9:
1,2,3,4,5,6,7,8: 9
for 17
1,2,3,4,5,6,7,8,9,10: 17
for 43
1,2,3,4,5,6,7,8,9,10,20,30,40: 43
for 357
1,2,3,4,5,6,7,8,9,10,20,30,40,50,60,70,80,90,100,200,300: 357
Baiscally, if N is 10 or under print the integers 1
to N-1, and then a colon and N.
If N is 11 to 100 print 1-9, then as many multiples of 10 as
will fit up to the number, then colon and N
If N is 101 up to 1000, print 1-9, then 10-100 by 10's, then
as many multiples of 100 as you can get smaller than N, then colon and N
When to change strategies
To keep this dynamic, put your strategies in a factory and have each
observer ask for a new strategy object every 3 printings. So the
Observer will start up with some strategy obtained from the factory,
print 3 reports with that strategy and then ask the factory for a
new strategy. The strategy factory will alternate inbternally in
handing out strategies (no matter which observer is asking)... first
it hands out a strategy 1, then next request (from anywhere) gives a
strategy 2, then back to 1, etc. This is a global back and forth,
so when any one observer asks for a new strategy it might get an object
that implements the same one it is currently using... but it wont
know that.
Basically the Observer knows it is time to get a new strategy,
but will not know which one it will get.

Each person will submit the solution done by the team via link on
their class webspace; each team member will
submit the same program code.
Put your source code files on the web so I can look at
them with a browser.

A10 (due 03/22/15 Sun. 11:59 pm ) (via web)

Do this assignment as a team. Develop the work together, then
each person will put the work on their individual class
assignment web page.

Develop user stories for the online voting system.
These user stories will serve as requirements for the
design you will produce. Use the issues developed in
class discussions as material for the stories, as well
the summary I have prepared.
You may also use your own ideas on how such a system should
behave to fill in where the class discussion was ambiguous,
spotty, or absent.

Submit the solution via your class assignment webspace.
Put your source code files on the web so I can look at
them with a browser.

This is a Java assignment. Use the code from class discussion
as a base.
One of the common ways to use factories is for an application
to have just one instance (object) for each facory class.
This naturally suggests the Singleton pattern.

a) Take the code for NameFactory and make the factory (class containing
the factory method) adhere to the Singleton pattern.
Alter the main app to demonstrate that an attempt to instantiate
a second NameFactory object fails.

b)
In the Abstract Factory example, a Garden makes Plants
so Garden is a Factory.
A GardenMaker makes Gardens, so GardenMaker makes Factories,
so it is a Factory Factory.
Take the code in for Abstract Factory and make the
garden factories adhere to the Singleton pattern.
Also then make the Garden Factory Factory (GardenMaker) be a Singleton.
Alter the main app to demonstrate that attempts to instantiate
these twice fails.

HOF takes three arguments -- let's call them p, f, and g.
When HOF is executed on some p, f, and g, it will
return a function... let's call that returned function R.

Here is how the returned function R should behave:
When we eventually execute function R we will give it two
arguments... the first is a non-negative integer, the second
can be anything. Function "p" will act like a "picker",
selecting which of function "f" or "g" to apply, based on
the first integer argument.

That integer will be passed to "p" as its argument.
If p returns a value greater than 1000 (or less than -1000),
then R will apply "f" to the second argument.
Otherwise, then R will apply "g" to the second argument.

Demonstrate your function by creating some function p,
some function f, and some function g, and explain what
you expect to happen when you run the function
created by your HOF on them. Show some executions to
support your explanation.
Write these at test cases in ML and include the tests
in the ML code you submit.

A5 (due 02/08/2015 Sun. 11:59 pm ) (via link in website)

Use ML to express the axioms you write. Using ML
will also allow you to check the behavior to see if you
have expressed what you intended.

Using Guttag's hueristic, give consistent and complete
algebraic specs for this ADT (class):

LIB (library)
new: -> LIB
add: LIB x BOOK -> LIB
rem: LIB x BOOK -> LIB
cko: LIB x BOOK x PERSON -> LIB
cki: LIB x BOOK x PERSON -> LIB
wait: LIB x BOOK x PERSON -> LIB
off: LIB x BOOK x PERSON -> LIB
has: LIB x BOOK -> boolean
here: LIB x BOOK -> int
num: LIB x BOOK -> int
new makes a LIB with no books, no wait lists, etc.
add puts another copy of a book in the library
rem takes a copy out of the library
cko allows a person to check out the book
cki checks the book back in;
if there is a person on wait list it does a cko to that person.
wait puts person at the back of a waiting list for a book
off takes a person out of the waiting list for a book
has tells if a book exists in the Library (even if all copies are
checked out
here tells how many copies of a book are available for checking out
num tells how many copies total of a book exist in the library

You can use string for PERSON. Use int for BOOK (like a simplified ISBN).

When picking the canonical constructors, consider the data structures
that must be kept internally by the library.
Some canonical constructor
will be needed to build each of these structures.

Hand in your work via the website you are keeping for the class,
the one you sent me the URL for in assignment A3.
Do it similar to
this web page and
this example, meaning make me a web page with a link to the text of each ADT in ML.
I need the ML source code to be cut-n-paste'able so I can
run the specs.

Email to me a URL for a web page that you will keep for this
class. On this web page please put your name and email adddress.
Then add links for your work as the semester progresses.
The page will include links to your individual work, as well
as to the work you do as a team.
ALSO, add a link for your A1 answer that you emailed to me.

I am not looking for pages, but I would like you to give it
enough thought that you can answer with a good paragraph or two.
Prepare this answer for the next class. Email it to me by the time I have
indicated so I can take a look before the next class, and so you will
be prepared to discuss this next time.