0% found this document useful (0 votes)
24 views

Lessons-Object Oriented Class Notes Revise Them

Uploaded by

reignskeem
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Lessons-Object Oriented Class Notes Revise Them

Uploaded by

reignskeem
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 33

object oriented programming paradigm

• •The object oriented paradigm is a methodology for producing


reusable software components
• • The object-oriented paradigm is a programming methodology that
promotes the efficient design and development of software systems
using reusable components that can be quickly and safely assembled
into larger systems.
• • Object oriented programming has taken a completely different
direction and will place an emphasis on objects and information. With
object oriented programming, a problem will be broken down into a
number of units .these are called objects .The foundation of oop is
the fact that it will place an emphasis on objects and classes. There
are number of advantages to be found with using the oop paradigm,
and some of these are oop paradigm
• • Object oriented programming is a concept that was created because of the need
to overcome the problems that were found with using structured programming
techniques.While structured programming uses an approach which is top down,
oop uses an approach which is bottom up.
Question
You are doing your attachment in one of the
software company and the project team leader who
is in charge of the project you are assigned to
implement with colleagues inquired from you to
explain to him why data hiding is supported by many
object oriented programming languages. Proceed
with your explanation.
Data hiding is supported to prevent external code
accessing the internal methods and variables of a
class. It ensures that external code does not have
access to partial information. It ensures that
contracts between the provider of a class and the
user of a class are fulfilled.
fields and methods in object oriented design and analysis

• Java classes contain fields and methods. A field is like a C++ data member, and a
method is like a C++ member function. In Java, each class will be in its own .java
file.

Question:
During an objected oriented class in St Paul’s University, students were asked to
implement different access level in fields and methods in there object oriented
practical quiz. Explain the access levels that the students were required to
implement.

Question:
the difference between an object in an object oriented language and a variable
• A variable is simply a name given to an area of memory which the program will
use. In a typed language the compiler is able to constrain what type of data is
placed into this memory location.
• An object also identifies an area of storage for data, additionally however, it also
determines what operations may be applied to that data
the responsibility principle

• The chain-of-responsibility pattern is a design pattern consisting of a source of


command objects and a series of processing objects.
• • Each processing object contains logic that defines the types of command objects
that it can handle; the rest are passed to the next processing object in the chain. A
mechanism also exists for adding new processing objects to the end of this chain.
• • Primary motivation is the need for a platform-independent (that is, architecture-
neutral)language that could be used to create software to be embedded in various
consumer electronic devices, such as microwave ovens and remote controls.
• • Objects with clear responsibilities
• • Each class should have a clear responsibility.
• • If you can't state the purpose of a class in a single, clear sentence, then perhaps
your class structure needs some thought.
• • In object-oriented programming, the single responsibility principle states
that every
• class should have a single responsibility, and that responsibility should be entirely
encapsulated by the class. All its services should be narrowly aligned with that
responsibility.
UML and function they serve in object oriented analysis and design.

i. Activity diagrams.
ii. Sequence diagrams.
iii. Class diagrams.
iv. State diagrams.
Construct a UML class diagram showing the
structure of a professional society, wherein
members pay an annual fee. Your class diagram
should incorporate the following 6 classes: member,
studentMember, standardMember, seniorMember,
society, and governingCommittee, which should be
connected with appropriate relationships, and be
populated with appropriate instance variables and
methods to enable the names, addresses and fees
of members to be stored, along with the
management committee members, and the name
and HQ address of the society. The governing
committee will comprise a number of senior member
The Library of Macmillan is a public library that stores various items that can be borrowed,
including books, journals, music, photographs and films. The Library is open to both
members and non-members, but only members can borrow items. There is a limit of ten
items in total that can be borrowed. Members must join first, by providing proof that they
live in the Birmingham area. The library also provides facilities such as Wi-Fi and
photocopiers, which both members and non-members can apply to use. Books can be
borrowed for two weeks and other items, such as music and films for one week. If the
borrower keeps the item longer than this, they are subjected to a fine, which is increased
daily. When a member borrows an item, they provide their libraryNo, if this is valid their
loan details are checked to ensure that the items to be borrowed will not take them over
the maximum number of permitted items. A check is also made to see if they have any
fines. If they have a fine, then they cannot borrow any items until the fine is paid. If all the
checks are ok, then the item is issued to the member and the return date is assigned to the
loan. At this point the member can optionally ask for a printout, which summarises all of
the items they have on loan and when each item is due back. Library members can reserve
items that are currently out on loan. If an item proves to be very popular, then the librarian
will order a new copy, provided the cost does not exceed the budget. Members can
register for online facilities so that they can check their own loan details at any time. Once
registered a member can also renew their loans online, provided that the item has not
been reserved.

•Write down a use case description of the way a member borrows a book. Your answer should
include a normal sequence and three alternative sequences
•Draw a use case diagram for the library system
Write down a use case description of the way a member borrows a book. Your answer should
include a normal sequence and three alternative sequences

•Sample use case description:


•Pre-Condition
•A member is registered with the library
•Actor Action System Response
•1. User requests to borrow a book
•2. Check libaryId is valid and provides libraryId
• 3. Check user not exceeded their maximum limit
• 4. Check user has no fines
• 5. If ok, book is loaned to user and return date allocated
•Alternative sequences
•Step 2. Invalid card, loan refused.
•Step 3. User has exceeded limit, loan refused.
•Step 4. User has fine, loan refused.
•Step 6. Request printout of loans
Draw a use case diagram for the library system
how object oriented code can be tested by use of UML diagrams

• An open-ended question. The Candidate may look


at different approaches, for example:
• Fault based testing
• Scenario based testing
• Sequence Diagrams
• Or may discuss black-box and white-box testing
with respect to OO programming.
• The candidate must discuss which UML diagrams
can be used for testing, e.g., Use Case
• scenarios
The Unified Modelling Language (UML) comprises of 13 different diagrams. These are
broadly categorised as follows

• i) Behaviour diagrams
• ii) Structure diagrams
• iii) Interaction diagrams
Behavior Diagrams

• Behavior Diagrams emphasize what must happen


in the system being modeled:
• Activity diagrams, which show the activities
involved in a process or in data processing
• State diagrams, which show how the system reacts
to internal and external events
• Use case diagrams, use case modeling is widely
used to support requirements elicitation.A use case
can be taken as a simple scenario that describes
what a user expects from a system.
Structure Diagrams

• Structure Diagrams emphasise what things must


be in the system being modeled:
• Class diagrams, which show the object classes in
the system and the associations between these
classe
• Component diagram
• Composite structure diagram
• Deployment diagram
• Object diagram
• Package diagram
Interaction Diagrams,

• Interaction Diagrams, a subset of behavior diagrams, emphasize the


flow of control and data among the things in the system being
modeled:
• Collaboration (UML 1.x)/Communication diagram (UML 2.0)
• Interaction overview diagram (UML 2.0)
• Sequence diagrams, which show interactions between actors and the
system and between system components
• Use case diagrams, which show the interactions between a system
and its environment and is widely used to support requirements
elicitation.A use case can be taken as a simple scenario that
describes what a user expects from a system.
• UML Timing Diagram (UML 2.0)
• For each category, the student should give a short description of one
of the diagrams, include simple example and say when they should
be used.
ways Unified Modelling Language (UML) can be used to design an
object oriented program

• 1 An external perspective, where you model the


context or environment of the system.
• 2. An interaction perspective where you model the
interactions between a system and its environment
or between the components of a system.
• 3. A structural perspective, where you model the
organization of a system or the structure of the
data that is processed by the system.
• 4. A behavioral perspective, where you model the
dynamic behavior of the system and how it
responds to events.
Object Constraint Language (OCL)

Explain how OCL might be used in the design of an object oriented


program.
It is good practice to produce a design for a program before coding
it.Typically in object oriented programming a design might be realised by
a set of Unified Modelling Language diagrams. The class diagrams
would set out the names of the classes, the names of the variables and
the names of the methods etc. Other diagrams would indicate other
aspects of the behaviour of the system. Many of these diagrams are able
to capture some aspects of the constraints which apply to the system.
UML diagrams, however, are not sufficient to express all possible
constraints nor are they able to precisely state the constraints they can
represent. OCL can be used to provide further details of the
requirements of system which goes beyond what can be achieved in a
UML diagram and allows those details can be represented in a very
precise way.
UML diagram

• Explain the following OCL statement:


• context Train Journey
• inv: passengers->size() <= train.number Of Seats.
Answer
The constraint says that for any train journey, the number of people travelling on a train making
The journey must be less than or equal to the number of seats on that train
• Or
• One train can do no journey,one journey or many journey
• Or
• Train journey can be no journey, one journey,two jouney many journey which can have no
passenger,one,two or many passengers
context of the Object Constraint Language (OCL) define the
following
• An invariant is a condition that can be relied upon to be
true during the execution of a program, or during some
portion of it. It is a logical assertion that is held to always be
true during a certain phase of execution.
• A precondition is a condition or predicate that must always
be true just prior to the execution of some section of code or
before an operation in a formal specification. If a
precondition is violated, the effect of the section of code
becomes undefined and thus may or may not carry out its
intended work.
• A postcondition is a condition or predicate that must
always be true just after the execution of some section of
code or after an operation in a formal specification.
Object Definition Language

Object Definition Language (ODL) is a specification language to define the


specifications of object types based on the ODMG ODL (but not
compliant). ODL is not intented to be a full programming language. It is a
definition language for object specifications. Database management
systems traditionally provide facilities that support data definition (using a
Data Definition Language (DDL)). The DDL allows users to define their
data types and interfaces while the Data Manipulation Language (DML)
allows to create, delete, read update instances of those data types.
ODL is a DDL for objects types. If defines the characteristics of types,
including their properties and operations. ODL defines only the signatures
of operations defined in C++ and does not address definitions of the
methods that implements those operations. Operations defined in OQL can
be defined in the ODL. ODL is intented to define object types that can be
implemented in a variety of programming languages. Therefore, ODL is not
tied to the syntax of a particular programming language.
EYEDB ODL differs from ODMG ODL from several points

1. ODMG ODL defines class attributes, relationships,


method signatures and keys. It supports nested classes,
typedef constructs, constant definitions and exception hints.
2. EYEDB ODL defines class attributes,
relationships, method signatures, attribute
constraints (notnull, unique, collection cardinality),
index specifications and trigger declarations. It
does not support nested classes, typedef constructs,
constant definitions and exception hints
in EYEDB ODL, any type instance can be both
a literal or an object.
In ODMG ODL, this property is tied to the
type:
all basic types and user defined struct are
literal while interfaces and classes are objects.
In EYEDB ODL, any type instance can be an
object, even the basic types
Defining a simple schema with ODL

Now that a database has been created, we are going to


populate it with objects.
The first step is to define the database schema.
A standard example in databases is the well
known Person class (or table in relational system) which
contains a few attributes such as a firstname, a lastname, an
age, an address, a spouse and a set of children.
We will show the inheritance feature through the simple
class Employee which inherits from the Person class and will
contains a simple attribute: salary.
Example 3.1, “The ODL schema” shows the ODL schema for
the classes Address, Person and Employee:
Example 3.1. The ODL schema
A few comments about this schema

the Address class contains four attributes, one integer and


three strings
ointeger: there are three types of ODL integers: 16-bits
integer, named int16 or short, 32-bits integer,
named int32 or int and 64-bits integer,
onamed int64 or long, so the num attribute is a 32-bits integer
ostring: an ODL string is under the form: string or string<N>.
The first form means that the string is not bounded, the second
form means that the string contains at most N characters
in the UML class diagram below for a university database answer the following
questions
In ODL, define a class student

• Answer:
• class Student {
• attribute string name;
• attribute Date dateOfBirth;
• attribute string address;
• attribute string phone;
• // plus relationship and operations . . .
• };
In ODL, define a class course

• Answer:
• class Course {
• attribute string crse_code;
• attribute string crse_title;
• attribute short credit_hrs;
• // plus relationships and operation . . .
In ODL, define user structures by
using the keyword struct

• struct Address {
• string street_address;
• string city;
• string state;
• string zip;
• }
• struct Phone {
• short area_code;
• long personal_number;
• }
• attribute set _ phone _ phones
In ODL,define the operations for
class; student.

• class Student {
• attribute string name;
• attribute Date dateOfBirth;
• //user-defined structured attributes
• attribute Address address;
• attribute Phone phone;
• //plus relationship
• //operations
• short age( );

You might also like