Lesson Summary Notes 1-10-OBJECT ORIENTED PROGRAMMING SLIDES NOTES UPDATED
Lesson Summary Notes 1-10-OBJECT ORIENTED PROGRAMMING SLIDES NOTES UPDATED
Lesson Summary Notes 1-10-OBJECT ORIENTED PROGRAMMING SLIDES NOTES UPDATED
Abstraction;
The most important aspect of a system model is that it
leaves out detail. An abstraction deliberately simplifies and
picks out the most salient characteristics.
Encapsulation
Object
MyClass myObject = new MyClass();
Method
Class MyClass{
Class MySubclass extends MyClass{}
how class creation is done in object
oriented and java
A class is created in the following way
+open():void
+lift(height:int):void
+tilt(angle:int):void
To make one, I type
BottleOfBeer myBeer = new BottleOfBeer();
If I want myBeer opened, I say
myBeer.open();
But Why Not Just…
BottleOfBeer myBeer;
This is legal, but just makes a “reference
variable” named myBeer
This variable can refer to any BottleOfBeer
object, but currently refers to nothing
The operator new actually causes an object to
be created, so we tell it what kind we want
Designers Design, Users Use
The interface is the critical part, but the details
(implementation) are important too.
BottleOfBeer
-topOn:Boolean
+open():void
+lift(height:int):void
+tilt(angle:int):void
+open():void
+lift(height:int):void
+tilt(angle:int):void
Patron
Two Ways of Reusing Classes
Inheritance: One class is a specialized version
of another (indicated by the triangle
“inheritance” symbol).
BottleOfBeer
BottleOfRollingRock
-lowCalorie:Boolean
+open():void
+lift(height:int):void +isLowCalorie():Boolean
+tilt(angle:int):void
Polymorphism
Different subclasses respond to the same
message, possibly with different actions.
Patron
+beerPlease():Polite
+beerPlease():Rude +beerPlease():InGerman
Some Java Code
Patron p1 = new Patron();
Patron p2 = new YankPatron();
Patron p3 = new BritPatron();
Patron p4 = new GermanPatron();
p1.BeerPlease() // polite request
p2. BeerPlease() // rude request
p3.BeerPlease() // polite request
p4.BeerPlease() // request in German (but polite)
The relationship is the association between the actors as well as it illustrate the actors that
are participating in a use case. Moreover, the use cases and the path relationships are
attach the diagram together. The purpose of the relationship is to explain that an actor is
basically involved in a use case, not involve an information exchange in any direction.
Relationships are represented by a line connecting between Actors and use cases. T
he relationships between use case diagrams in UML have different type: 1- Includes
relationship. 2- Extends relationship. 3- Generalizations relationship.[16][15]
Include relationship:- The include relationship is used to indicate that one use case has
explicitly contains the behavior of another use case to execute its function. Moreover,
include relationship has two types of use cases that illustrate this situation, firstly
including use case which required the functionality from another use case, and the second
kind included use case which is included in the first, including use case. The includes
relationship is represented by dashed line with open arrow head which connected the
include use case including use case started at including use case and ending at the include
use case, as well as the ward <<include>> enveloping with guillemot is written Along the
line . When develop the system into an application the included use case is facilitated to
identify where can reuse functionality, which is major, advantage of design and
development.
Extend relationship:
The extended relationship is used to indicate that use case
completely consists of the behavior of another use case at one or
specific point, which mean inheritance between the class in C++.
The notation of extended relationship is similar that to include
relationship. Furthermore, the use case of the include relationship
might totally use again with another use case behavior but in the
extended relationship the reuse was optional depended on system
achievement decision ,as well as the Extends relationship is a
conditional include . Extends relationship is represented by
dashed line with an open arrow head and along the line is written
“<<extend>>", enclosed in guillemets. An extend relationship
points the line started at the use case which is conditionally
include the other use case. [16][15]
Generalizations relationship:
The generalization relationship is used to represent that the
parent use case identify behaviour that its children can
inherit, and the child can add or override to that behaviour,
as well as Generalization can be related to both actors and
use cases to represent that the child inherit functional from
parent .Furthermore, Generalization can separated more
than two child use case as well as generalization can be
hierarchal. Moreover, the use case inheritance is helpful to
show that one use case is special kind of another use case.
The generalization relationship is represented by a solid line
with a hollow triangular arrow. The arrow is drawn
indicating the direction of the Generalization.[16][15][17
Class Diagram
The system static structure can be documented by
class diagram. All system life time can be shown on a
links (associations) between classes with their
operations, attributes, and names. Class diagram
define as a rectangular boxes .This boxes initially
contain sections. First section gives for class name (or
object name), second one contain the class attributes,
and the bottom section for methods (operations)
associated with the class as shown below
Each object has a class in class diagram .This object
may be a person, thing, place, or event for our
system. In attribute section (…) indicate that there
are other attributes related to that class. Before build
a class, you should make a good class model that
help to understand the system behavior. The class
must meet all the system criteria, and realize the use
case diagram, otherwise that the class model can not
work well, whatever the techniques are used to build
the class
The class building should:
• Design it in cheap and quick ways, this mean each point required in
system behavior must provide in sensible way, by the object of the
class.
• Design a system to easy maintain and flexible to add future
requirements. If object needs to update ,this should be easily done
and should the designer keep a track to that object for any new
changes ,such as when the super market change the item cost ,the
updated values carry on directly to the system data base without need
to make a new design or add other class for that! .
A good class represents permanent classes of domain objects,
which do not depend on particular function, this mean a name
of class to call it is need to be clearer .example in the member
class for library system gives the indication of the class
contents rather than call the class moon, people in library or
any name not related to class attributes! • The design of
classes should be chooses carefully and makes sure each class
has a link with other class. Do not build a class without have
work to do it. • The model design must contain all the
description of what should the system do. • The class name
should be a noun. The attributes are name phrases, the
methods have a verb sentences, and the links (association)
between that classes contain the exact operations between
them such as: is a , part of, contain, has a …etc.
Attributes
Any class cannot make it process without
addressing the states and behavior of that object.
It should have the attributes middle section of
object (or class) box with lower case letter for
each name. Each object have own attributes and
they gives the all information that object have. In
library system the member object attributes are:
member ID, member name, address, phone no. ,
e- mail. All those have unique information for
each member in library.
Attributes
Some attributes values could be changes during system life
time and this should included in the first steps of building a
system class diagram as we mentioned in good class points.
In library, sometimes the member changes the phone no. or
address ,but in address changes ,the good actor(designer) for
class design need to add new class name address .Because
the addresses have complex lines and many information, also
the address object could be used from other class not for
member class only .It may use for librarian class. This
method reduces the interactions loads on system behavior.
Some type of class diagram add the attributes information
within class diagram like member class, also can but the
programming languages arguments such as title: string,
name: char ….etc as show in copy class below
Multiplicities
Operations
Operations are located in third (bottom) class section. They
must define in each class box, because the object (class) did
not know what should do and which other class should
interact with. The operation tells object what is the message
passed to the receiver object, and the last one invoked that
message to perform operation. The familiar format for
operation as shown in fig 4 gives (visibility name
(parameters): type), Take a copy() :char There is a tight
relationship between object state and operation .the object
attributes can not change or update it values by it self.
The object needs to have a service that wraps the assists modularity
in a system life time. This service can provide it only at object’s
interface .It contain a signature for each operation to avoid the
conflicting during sending or receiving messages between system
objects. Normally the object just respond to a simple quires .There
are objects need to send a message that have a valid call on an
operation.
The operations write in verb sentences lower case letters to give the
indicate about what the class (object)need to do and which other
class(receiver class)operations or attributes are related to that
operations .In class diagrams the generalization operation gives
important concepts. In library system we can call a library member
is generalization of librarian, because each librarian is already a
member of library. This go to other class diagrams relations such as,
aggregation, composition, association class, interface, and others.
They classified in table below.
Generalization:
Generalization: in example below, the engineer, and doctor are goes to
one people (human) class .they generalize, or inherit a people. We can
call doctors, engineers, teachers are people, but never called the people
are doctor! Generalization goes in one way from children class to
parent’s class.
Aggregation:
All details that are not directly related to the collaboration will be
suppressed. At this stage, the class diagram might not really tell the
whole story of the system. But as the design continues, more
information will be added. The diagram will eventually form the
picture as the model transform again. It is very important that the
consistency of all diagrams used is maintained especially during the
realisation process. At the end of realisation process, both the use
case and class diagram should have structural and notational
similarities to the collaboration. There should be a class for each
nodes and each classes have associations that link them. Some class
might not have any relationship yet but will be added in later stage.
The end result must have all class correspond with a relationship
Discuss how object oriented code can be tested; within your
answer explain which.UML diagrams can be used to aid testing.