View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Anita Lugonja

Anita Lugonja
gtg882u

EXTRA CREDIT
Stack Overflow


CoWeb Assignment 3

Design Patterns (2 Points)
(Part A)
Besides its name, name three characteristics commonly used to describe design patterns.
For each characteristic, describe what it is and why it is useful?

Three charasteristics that are commonly used to describe design patterns:

1. Intent: describes how to solve the problem

2. Participants: describes the participants for the design,
including interfaces and methods needed for the design.

3. Consequences: are the results and tradeoffs of a design pattern.
It is important for a user to understand the consequences of design patterns,
so he can handle them appropriately.



(Part B)
Observer, Adaptor, and Factory are three design patterns described in this class.
For two of these three, briefly describe them using the characteristics you chose.

Observer

1. Intent:
Define a one-to-many dependency between objects so that when
one object changes state, all its dependents are notified and
updated automatically.
2. Participants:

(Abstract) Subjects: Know observers and can attach/detach them
(Abstract) Observers: Can update when notified of changes

ConcreteSubjects: maintain state for subject
ConcreteObservers: maintain a relationship with the ConcreteSubject

3. Consequences:
Abstarct coupling between Subject and Observer which can be an
issue in large multi-layered system
Needs support for broadcast communication to add/remove
observers anytime, which can be computationally expensive.
Unexpected updates because of sending messages between
observer and subjects.


Factory

1. Intent:
Define an interface for creating an object,
but allow subclasses which class to instantiate.
Factory method will decide which object to give you,
according to the given parameters. Example: Word Processing
and Spreadsheet documents.

2. Participants:

Product: Defines the interface of objects that the
factory method creates ( for example, documents can open, save,
close, etc.)

ConcreteProduct: Implements the Product interface.

Creator: Defines the Factory Method

ConcreteCreator: Overrides the Factory Method to create
an instance of ConcreteProduct.

3. Consequences:
You need to have a ConcreteCreator class for every product
you create; you need to provide hooks for subclasses.
Factory method connects parallel class hierarchies which
makes class evolution and development more complex.




Frameworks (2 Points)

Why are frameworks useful?
Frameworks are useful because they are a reusable design for
software system. They are expressed as a set of abstract classes and
the way their instances collaborate for a specific type of software.
This way developer can use the frameworks instead of writing everything
from the scratch.

What is the difference between a framework and a class library?

There are three main differences between a framework and
a class library:

i) Frameworks use inheritance more heavily
ii) Frameworks evolve more quickly
iii) Frameworks are often modified on the spot if they
are not qiute right.

List two of the Squeak frameworks covered in this class and what
they provide.

Sunit is a testing framework for creating and running unit tests.
Sunit checks results against expected results and reports which
test is broken. It also has a built-in initialize before a test method
and clean-up after test method.
Sunit allows programmer to test their code by deriving class from
TestCase and writing any set up in setUp method, clean up in
tearDown method,and test methods in testNameOfTestMethod.
The generic test code already exists, so it makes it faster for
programmer to write test cases.

Morphic allows programmer to create new objects that already have many
features. This way programmers do not need to implement these extra
features.




Explain two of the reasons that a framework is difficult to develop.

Frameworks are difficult to develop because of the complexity.
Developing complex software is very difficult and it is even more
difficult to develop high quality, extensible, and reusable
frameworks for complex applications.

Another issue is the learning curve or usabilty. It may take a long
time for developer to figure out how to use frameworks, depending
on the developer's experience. In order to effectively
use frameworks it is necessary to have trainings and well written
documentation.




CoWeb Assignment 2
Debugger

Using debugger in Squeak is very usefull.
When you get an error in Squeak it pops up a window that tells you the name of the error.

Uploaded Image: error.jpg

You have three options: Proceed, Abandon and Debugg. It also gives the list of all sent messages. The last message sent is on the first line. Each message calls one above it.

If you click proceed, it takes you to the next step.
If you click abandon it closes the error window.
If you click debug the next window occurs.


Uploaded Image: debug.jpg

The top pane lists all methods that were in execution when this errror occured.
When you click on some line from the list the method from that line is displayed in the middle pane.

The left two lower panes are showing the instance variables for the object being debug.
The right two panes are showing the local variables and the arguments to the method.
You can right click on any of these variables and inspect it.
You can also change and save the code inside the debugger.

For example, we are in the MediaStudioclass in the method step.
The error is highlighted. In the two right lower panes we can see that variable each is nil and
variable actors is also nil. If you inspect actors it will say that it is an undefined object.
That is the reason why the error has occured. The next images shows that object actors is not defined.

Uploaded Image: UndefinedObject.jpg

CoWeb Assignment 1
Tracing Code

The following code solves the rainfall problem, which you may have seen in previous CS classes. For each line, describe what the Smalltalk code does. Be as specific as possible. In particular, what is data at the various points in the code?

| data onlyPositiveNumbers |
This line declares temporary variables named data and onlyPositiveNumbers.
They are not initialized, so they are set to null.


data := OrderedCollection withAll: #(1 2 3 -4 -5 'error' 6 -7 999 2).
This line sets data to be an ordered collection with the values in parenthesis.
So, data contains: 1,2,3,-4,-5,'error',6,-7,999,2.
In this case 'error' is a string.


onlyPositiveNumbers := [:i | (i isKindOf: Number) and: [i positive]].
This line assigns the [:i | (i isKindOf: Number) and: [i positive]] block of code to onlyPositiveNumbers.
This means that for a given variable i, i has to be a number and i has to be positive.


data := data select: onlyPositiveNumbers.
This line sets data to only positive numbers. It will iterate through each element in data
and it will select only positive numbers. So, data will contain: 1,2,3,6,999,2.


data := data copyUpTo: 999. "not including"
This line will set data to the copy of data up to 999, not including 999.
So, data will contain: 1,2,3,6.


Transcript show: data average
This will print the average of data, which is 3.


Writing Code

Implement a method in Squeak that will give you the nth Fibonacci number. For both 0 and 1, the Fibonacci number equals 1. From then on, the next in the series is simply the sum of the previous two in the series (1, 1, 2, 3, 5, 8, 13, 21, 34, 55, etc.). Return an error when applicable. Your code should be based on good OO-style and be an efficient algorithm.


Fibonacci

((self = 0) | (self = 1)) ifTrue: [^1].

(self > 1) ifTrue: [^(((self-2)Fibonnaci) + ((self-1)Fibonacci))].

^'invalid input'.

Add Fibonacci method in Integer class.
Then for example,
Fibonacci 5 returns 8.







Links to this Page