A class is just what it sounds like, a type of something, think weight classes. I
for example am a heavyweight. A class describes something and how it functions
internaly. A class has class variables and instance variables. Class
variables are shared among all members of that class; there is only one copy of class
variable. Every object, or istance, of a class has all isntance variables inherent to
that class. Also, there are class and instance method. The basic difference is
that a class method does not require an object, the new message for example.
Instance methods however work on an already created object, and example being an
accessor or modifier.
Message passing is how objects in Smalltalk and Squeak communicate with each other. A
message could request data from another object, or it could inform another object of a
change that has occured. Message passing works with class-based inheritance in that
all decendents of a class that responds to one message will all respond to that message.
Message passing is useful in that it can allow for efficient error handling and it
provides good encapsulation. It is a problem in that it can be harder to get to data,
there must be a message for everything and outside objects can't modify the object.
Coweb Assignment 3
One of the things used to describe a design pattern is its intent, i.e. what the problem this
design pattern is created to fix. A second aspect of design patterns is their implementation,
the method to use in using the pattern. A third aspect of design patterns is their participants,
what classes and objects will be involved in the pattern.
Observer: An Observer is a design pattern for having one class looking at another for changes. The intent of this pattern would be to used when one or a series of obejcts need to know when another object is altered. In the implementation of the observer pattern, an observer is given to the object to be observed and added to its list of observers. When something happens in the class that is being observed, it tells all of its observers. This way, the class that is doing the obvserving doesn't have to actively look to see if the observed class is changing. The participants of the observer pattern are the object to be observed and its list of observes, which it will notify if the object is changed.
Factor: The Factor design pattern is a way of creating a predefined object. The intent of this design pattern is to have it so that objects can be created in predefined ways without having to do it in the code. The Factory needs to have methods that will return new instances of a class when asked for them, and they need to return a fully functional object. For example, the BorderFactor in Java will return new objects to represent to the borders for the window without the user having to program their own borders each time. The participants in the Factory patter are the object that calls up the methods of the factory, the factory itself and what ever object the Factory creates and returns.
Object-Oriented Language Design
1.) One main advantage of having primitive types is speed. Object creation is not very fast.
If the VM has to create a new object every time a number is needed, then it will really slow
things down. It will also suck up memory until the garbage collector comes by. Primitives,
however, cannot contain methods and messages cannot be passed to them like other objects. Java
gets around this by having wrapper classes like Integer. Also, having primitives as objects
allows them to kind of check themselves for errors or overflow. This allows for more
encapsulation and all that good junk.
3.) The virtural machine takes bytecode from a program running under it and turns it into
things that the system it is running on understands. Obviously, this will not be as fast as
compiled code running natively under a system as there is an extra layer of translation to go
through. Consequently, C++ will run faster than Java, or much faster than Squeak, though I
Java uses some kind of virtual machine/true program mix. One big advantage of the virtual
machine is garbage collection. No destructors and stuff like in C++, so you don't have to
worry so much about memory management. Also, having a VM allows you to get more detailed info
about any errors that come up. Obviously, without the VM you won't get htat and have to rely
on things like logging and printing.