Software Engineering Project
Lecture: OOP and GUI Design
Object Orientated Design:
I have found object orientated programming a very enjoyable programing
paradigm. The program is easily maintained and extendable.
The programming language helps to structure the program. Also the
programming language is very flexible.
Aspects of OOP that are particularly useful are:
-
Classes and Objects
Classes are the abstraction, while objects are related to the real
world concretely. Each object is an unique member of a class.
Classes permit describing the system in global terms with out worrying
about the implementation.
-
Encapsulation
Wrapping data and methods within classes in combination with implementation
hiding is often called encapsulation. The result is a data type
with characteristics and behaviors. Classes can encapsulated other
classes in the data fields. This implies that programmer clearly
delineate access, public/private. This guarantees that the
implementation can freely modify private methods and data without
breaking the users code. Note that encapsulation defines both knowledge
(data) and behavior (methods).
Objects collaborate between them selves by sending
messages to
each other. The object sending the message called the client
and object providing information is called the server. Note
that the client does not know how the server provides the service.
A physical picture of a class and encapsulation is a doughnut
with the circumference of the doughnut representing the public method/interface
and private methods and fields contained inside the doughnut, encapsulated.
Encapsulation of a class by instantiation of a class in another class.
This is frequently called composition.
Sometimes it is convenient to have two objects communicate without using
a class encapsulating the two object. This is can be done by provide
references to the two communicating class in each other class definition.
This technique is not strictly composition. The technique is not
preferred by software engineers because it leads to tightly coupled code.
The two classes can not exist independently and this may not be clear to
a client.
-
Hierarchy/Inheritance
Inheritance provides a means to be more specific or too add features
to a class without touching or even knowing how the original class is implemented.
The more general class, typically the class with fewer methods and field,
is called the base or super class. The class
derived from the super class, generally the more specific class, is frequently
called the derived or sub class.
We can determine weather to use encapsulation or inheritance by asking
ourselves is-a or has-a object? Is-a implies inheritance
and has-a implies encapsulation.
-
Abstract/Interface Classes
Abstract classes are classes that are never instantiated. They are
useful for defining commonality. Interfaces are also a contract to
client of the minimum set of services he can expect from a class that implements
or extends the interface.
-
Polymorphism
Random House Definition: having, assuming, or passing through many
or various forms, stages, or the like.
In OOP common method names execute differently depending on the client.
This allows large section of code to be written in terms of the base class
methods without worrying about the specific derived classes. Then
as new derived classes are added we do not have to rewrite the code that
uses the base class.
-
Frameworks and Patterns
Design patterns and frameworks are standard techniques to solve problems
or design programs. Patterns tend to be more algorithmic and frameworks
more structural.
A typical OO design process for teams is the CRC card technique.
A similar procedure that can be used by an individual is:
-
Restate project specification:
Make sure you are clear on the problem you are solving.
-
List candidate classes:
Brian storm a list of candidate classes. While brian storming
remember all ideas are potential good ideas. Think fast and furiously
first, ponder latter.
A good source of classes are the nouns in the project statement.
Be careful and stay on track. Solve the current problem with an eye
to what is to come. Recall java classes represent real life objects.
-
Identify key classes:
-
Identify critical, irrelevant and undecided classes
Divide the classes into the three groups. Critical classes will
probably appear in all the sources for classes. Critical classes also undergo
change of state. Irrelevant classes are typically on outside or on the
edge of the main system.
-
Clarify project scope
Be sure to identify the scope of the project or be prepare to never
finish. Use/make a scope diagram; and this will help identify critical
and irrelevant classes.
-
Avoids phantoms and aliases
Phantom classes are typically without sufficient substance (belong
to a class) or fall outside the domain.
-
Distinguish Attributes from Classes
Attributes belong in a class and are not classes. Typically they
represent the class.
-
Specify classes:
Class can be specified by a diagram. The diagram is a box with
the name of the class high in the box below the name is a horizontal
line followed by a list of method names.

This is very similar to an java interface. I frequently use interfaces
to implement this part of the design. Also interfaces allowing me
to continue programming without worrying about how I will implement a class.
-
Diagram class hierarchy
When I have to code programs with complicated class hierarchy structure
I use diagrams. Objects are represented by boxes with the class name towards
the top sometimes followed by a list of methods. Composition of two
objects is indicated by a line connecting the two object. A small
dark diamond near one of the objects indicates the encapsulating object.
Inheritance is indicated by arrow from the derived object to the base object.
An example of diagramming the three classes; Shape, Square, and Edge.
Note a Square is a Shape and has four Edges.

Sometimes a reference to another class is represented by an open
diamond.
-
Evaluate classes and hierarchy
The characteristics of a good class are:
-
Clear unambiguous name that is a singular noun and begins with an uppercase
letter
-
The class has responsibilities (methods) and as knowledge (fields).
-
The class collaborates with other classes and actively participates in
the system
The class hierarchy and structure should be simple and not tightly
coupled.
Use a classes with your use-cases.
Graphical User Interface Design:
In many aspects the gui is the most important part of the program.
The gui can determine if the user enjoys or hates using the program.
If the user hates using the program he will stop using it. Interesting
that in industry there are generally no gui expert; all programmers are
expected to be able to write good and effective gui.
Typical user interactions with the computer are:
-
Question and answer
This is the old style input to the program. Easy for the programmer
to implement and not hard for the user to learn. The inputs to the
program are rather limited integers or strings and is very slow for the
user.
-
Direct manipulation
Example of direct manipulation are games and drawing software. For
the user direct manipulation is fast and intuitive, but for programmer
can be hard to implement.
-
Menu selection
This type of input is typical for many software programs. The
interaction avoids error and offers choices. For experience user
the interface is slow. The java programmer can easily implement menus.
I also include AWT radial buttons.
-
Forms
Typical form use are spread sheets and text field in java AWT.
I also include AWT sliders with forms. For the user the data input
is reduced and is easy to learn. Also easy for the java programmer
to implement.
-
Command language
Example is unix operating system. Hard for the user to learn,
but once learned very flexible, powerful and fast. Can also be incorporated
into scripts further increasing the power of the user interaction.
Very easy for the programmer to implement.
-
Special hardware interface
Examples are scanners in the groceries and touch screens. The
interface is very fast for the user, but is expensive and generally single
task dedicated. The programmer needs to at least learn a new api.
-
Natural language
A example is search engines on the www. Very easy for the user to use
but requires more typing and not always reliable. Can be very difficult
to program; at a minimum requires a parser.
Besides input to the program, the program also need to provide output.
Presentation of the data can be graphs, text or sound. It is generally
a good idea to keep the presentation of data separate from the data.
In other words the same object that keeps and creates the data should not
present it. Keeping the presentation separate allows maximum flexibility
of the presentation. The user can request different ways to present
the data. Generally information should be presented in text only
when precise values are required by the users otherwise graphical presentation
of the data is preferred.
The gui programers should always consider the user, his expertise and
experience using computers. The principles of designing a gui are:
-
Friendliness
The gui should use terms and input techniques that are know to the
users
-
Consistency
Similar operations should produce similar results. This helps
to minimize memory requirement for the user and reduces surprise.
-
Error response
The gui should be able to recover from user error.
-
User guidance
The gui should provide feedback, meaning that the user should know
that his commands have been accepted. The gui visual presentation
should be obvious to the user and instruct the user how to use the program.
For example context sensitive help.
-
Beauty
No one likes to look at something ugly.
From my personal experience, the best tools for gui design are drawings
of the windows and use-cases. Use-cases are good for checking that
gui performs the use tasks efficiently.
Because the gui presentation is so important to the program's success,
it is important to get a mock-up gui to the client has soon as possible.
A mock-up gui is a program that opens up the window with the menus, text
fields etc. but when the user makes a selection the program only output
a text message to standard out.
If you are not familiar with the gui programming refer to Objects
have Class, chapter 14, Graphical User Interfaces. Also study the
java api at http://java.sun.com/j2se/1.4/docs/api/
in particular study the java.AWT and javax.swing packages. Sun web
sites have excellent tutorial at http://java.sun.com/docs/books/tutorial/
in particular the swing tutorial at http://java.sun.com/docs/books/tutorial/uiswing/index.html.
Now is the time to read the second project assignment.