Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007
1. Frameworks are useful in the sense that it can greatly reduce the cost of application development by letting the application programmers reuse both design and code.
2. A difference between a framework and a class library is the fact that a framework uses inheritance more heavily in order to provide a more guided or enforced design of a given problem domain to the application developers. Also, a framework is more likely to be modified therefore evolve faster than a class library.
3. SUnit is a unit test framework for Smalltalk. Sunit framework is used by application developers to create and run their unit tests in a more systematic manner. SUnit framework provides ways for its user to initialize before and clean-up after a test, check results against expected results, and report bugs.
Another framework discussed in class is Morphic. Morphic is a framework that let application developers build a user interface with graphical objects called Morph. All displayable objects in Morphic framework are subclasses of Morph.
4. A framework is difficult to develop for the following reasons. A framework has to be quite easy to learn for developers and still has to provide all the functionalities required in the given problem domain. Domain analysis has to be performed before building a framework. Another reason is that frameworks involve real code unlike design pattern. It means that you have to pay attention to small details of different programming language features and syntax.
Object-Oriented Language Design(2points)
1. One advantage of having primitive types is speed. It is much faster to operate on a primitive typed variable.
Also, in some aspect, primitive type can be much more memory efficient. For example, consider a case where you only need to store an integer value to a variable. In a language that supports primitive types like C++, you can simply declare a variable int, which then will allocate only 32 bits. However, in Smalltalk where everything is an object, whatever the size of Object class will be allocated. Normally, size of an object is much bigger than 32 bits.
Main disadvantage is that primitive types cannot be expanded to allow generic operations to be performed on.
3. Advantages and disadvantages of using a virtual machine for OO programming.
There are number of advantages of using virtual machine. Virtual machines allow application developers to write programs that are platform independant.
Virtual machines provide a very convinient feature called garbage-collection to programmers. The garbage collection feature basically set programmers free from always having to worry about pointers and memory leak.
Also, virtual machine is what makes late-binding possible.
The biggest disadvantage of virtual machines is speed. You just can hardly make a program running on virtual machine faster than a program that is compiled and optimized for its running platform.
here's my fibonacci code in squeak.
| ret a b |
(n isKindOf: Integer) ifFalse: [ ^self error: 'Err. only non-negative integer allowed!!!'].
n < 0 ifTrue: [ ^self error: 'Err. no negative integer allowed!!!'].
n = 0 ifTrue: [ ^1 ].
n = 1 ifTrue: [ ^1 ].
a := self fibonacci: (n-1).
b := self fibonacci: (n-2).
ret := a + b.
Swing as MVC
Swing architecture is based on MVC, but it is slightly different from the MVC structure seen in Squeak.
Model in Swing is basically the same as in Squeak. However, The differenc is in the level of coupling between View and Controller. In Squeak, View is a class, and Controller is also a class of its own. In Swing, View and Controller are highly coupled. Instead of seperating Controller from View, Swing combines View and Controller into an object called Delegate. You can find the mother class of Delegate in javax.swing.plaf.ComponentUI. So basically, if you'd want to create your own view and controller, you should create a subclass of ComponentUI class. ButtonUI is a simple example of a subclass of ComponentUI. If you want to have a model for ButtonUI, you implement the ButtonModel interface. DefaultButtonModel class which implements the ButtonModel interface can be found in Java API. The way dependancies between Model and View work is pretty much the same as in Squeak. If you see the ButtonModel interface API, you should see "addChangeListener" method. Any view class who wants to be notified when the model changes, it registers its ChangeListener to the model. The model knows nothing of the dependant view class. The model simply keeps a list of ChangeListers and notifies the views upon changes in its values or state.
CoWEB assignment 2
Squeak Debugger Tutorial
A debugger is probably one of the most essential tools for a programmer regardless of which programming language is used. Luckily, Squeak provides a debugging tool equivalent of GDB. I will assume the readers of this tutorial have at least brief experience using GDB or GDB-like-tools.
When programming in squeak, most of you probably have seen an error notifier saying "MessageNotUnderstood". This error occurs when an object is passed a message that is not understood by the object. Here, it is likely one of the two cases. Either, you carelessly made a syntactical error such as misspelling, or the object to which the message is passed is not of the class type that you originally intended at that exact moment. Debugger can be especially useful in the latter case. To open up the debugger from such error or exception notifier window, click on "Debug" button.
It will open up the debugger.
The top part of the debugger displays the current call stack. The middle part shows the sourse code of the method that is highlighted in the call stack. The bottom part displays the current(run-time) contents of the object and local variables and arguments of the method. For example in the screenshot, if you select the local variable "test", the debugger shows the content of the "test" variable, which is currently "nil". So, here you know why you got the "MessageNotUnderstood" error.
Besides just inspecting run-time objects, the debugger does more useful things by letting us control method execution. Right inbetween the call stack and the source code, there are several buttons horizontally lined up. "Over" button works like "next" of GDB. It executes the next method. "Into" button is like "step" of GDB. It will step into the next method. "Proceed" is like "continue" of GDB. It will basically close the debugger and resume running.
Sometimes, instead of waiting until something to go wrong to bring up the debugger, you might want to open up the debugger at any point you'd like.
In that case, you can insert "self halt" wherever in the code you want the debugger to start running.
Links to this Page