object oriented programming with c++ - uranchimeg.comuranchimeg.com/ec203/mec203lec02.pdfm.ec203* --...
TRANSCRIPT
M.EC203* -- OOP (C++) -- Lecture 02
Object oriented programming
with C++
T.UranchimegProf. Dr.
Power Engineering School
http://www.uranchimeg.com/
M.EC203* -- OOP (C++) -- Lecture 02 2
Subjects
• Object Interactions
• A message
• Inheritance
• Polymorphism
• SDLC
M.EC203* -- OOP (C++) -- Lecture 02 3
Exercise 1-001
M.EC203* -- OOP (C++) -- Lecture 02 4
True table
M.EC203* -- OOP (C++) -- Lecture 02 5
Exercise 1-002
From previous
table make
UML notation
M.EC203* -- OOP (C++) -- Lecture 02 6
Exercise 1-003
M.EC203* -- OOP (C++) -- Lecture 02 7
Instance of class
M.EC203* -- OOP (C++) -- Lecture 02 8
Object Interactions
Objects interact by sending
messages to each other. The
object that sends the message is
the requestor of a service that
can be provided by the receiver
object.
M.EC203* -- OOP (C++) -- Lecture 02 9
A message
The object's interface consists of a set
of commands, each command
performing a specific action. An
object asks another object to perform
an action by sending it a message. The
requesting (sending) object is referred
to as sender and the receiving object is
referred to as receiver.
M.EC203* -- OOP (C++) -- Lecture 02 10
Object and message
M.EC203* -- OOP (C++) -- Lecture 02 11
An example
For example, a School object
asks the Student object for its
name by sending it a message
asking for its name. The
receiving Student object
returns the name back to the
sending object.
M.EC203* -- OOP (C++) -- Lecture 02 12
An message
A message can also contain information the sending
objects needs to pass to the receiving object, called
the argument in the message. A receiving object
always returns a value back to the sending object.
This returned value may or may not be useful to the
sending object.
M.EC203* -- OOP (C++) -- Lecture 02 13
The example
For example, the School object now
wants to change the student's name. It
does this by sending the Student
object a message to set its name to a
new name. The new address is passed
as an argument in the message. In this
case, the School object does not care
about the return value from the
message.
M.EC203* -- OOP (C++) -- Lecture 02 14
A message
A message contains
three parts:
M.EC203* -- OOP (C++) -- Lecture 02 15
Some example messages
M.EC203* -- OOP (C++) -- Lecture 02 16
Message structure
1. A receiver object
2. A method the receiver
knows how to execute
3. An ordered set of
parameters that this method
requires to carry out its
function
M.EC203* -- OOP (C++) -- Lecture 02 17
Message structure
1. The operation to be invoked or started,
which is the service requested and
must be an accessible operation
2. The input data required by the
operation to perform, which is known
as the arguments
3. The output data, which is the reply to
the message and is the actual result of
the request
M.EC203* -- OOP (C++) -- Lecture 02 18
Message signature
In order for a message to make
sense, the sender and receiver must
agree on the format of the message.
This format is stipulated in a
message signature that specifies
the name of the method to be
executed and the parameters to be
included.
M.EC203* -- OOP (C++) -- Lecture 02 19
Inheritance
Another important concept of
object-oriented programming is
inheritance. Inheritance allows a
class to have the same behavior as
another class and extend or tailor
that behavior to provide special
action for specific needs.
M.EC203* -- OOP (C++) -- Lecture 02 20
Example
Let's use the following
application as an example. Both
Graduate class and
Undergraduate class have
similar behavior such as
managing a name, an address, a
major, and a GPA.
M.EC203* -- OOP (C++) -- Lecture 02 21
Continue
Rather than put this behavior in
both of these classes, the behavior
is placed in a new class called
Student. Both Graduate and
Undergraduate become subclass
of the Student class, and both
inherit the Student behavior.
M.EC203* -- OOP (C++) -- Lecture 02 22
Example
Both Graduate and Undergraduate classes can then
add additional behavior that is unique to them. For
example, Graduate can be either Master's program or
PhD program. On the other hand, Undergraduate
class might want to keep track of either the student is
Peter, Junior or Senior.
M.EC203* -- OOP (C++) -- Lecture 02 23
Super and sub class
Classes that inherit from a class are
called subclasses. The class a
subclass inherits from are called
superclass. In the example, Student
is a superclass for Graduate and
Undergraduate. Graduate and
Undergraduate are subclasses of
Student.
M.EC203* -- OOP (C++) -- Lecture 02 24
Subclasses of the Vehicle class
M.EC203* -- OOP (C++) -- Lecture 02 25
Polymorphism
he ability of different objects to respond to
the same message in different ways is
called polymorphism, a Greek term
meaning "many forms." The term can be
intimidating, and polymorphism is often
considered an advanced concept in object
technology. But the basic idea couldn't be
simpler: Each object can have a unique
response to the same message.
M.EC203* -- OOP (C++) -- Lecture 02 26
Polymorphism example
Can be send same message to
objects but can be returned
different result.
M.EC203* -- OOP (C++) -- Lecture 02 27
Lifecycle of program
M.EC203* -- OOP (C++) -- Lecture 02 28
SDLC
A Systems Development Life
Cycle (SDLC) is any logical
process used by a systems analyst
to develop an information system,
including requirements,
validation, training, and user
(stakeholder) ownership.
M.EC203* -- OOP (C++) -- Lecture 02 29
SDLC
M.EC203* -- OOP (C++) -- Lecture 02 30
Waterfall model
M.EC203* -- OOP (C++) -- Lecture 02 31
Spiral model
M.EC203* -- OOP (C++) -- Lecture 02 32
V model
M.EC203* -- OOP (C++) -- Lecture 02 33
Software Product Engineering Lifecycle
M.EC203* -- OOP (C++) -- Lecture 02 34
Requirement and result
M.EC203* -- OOP (C++) -- Lecture 02 35
Exercise 2-1
2-1. Обьектуудын харилцан
үйлчлэлцэх арга юун дээр
тулгуурладаг вэ? Жишээгээр
тайлбарла.
M.EC203* -- OOP (C++) -- Lecture 02 36
Exercise 2-2
2-2. Өгөгдлийг яагаад нуудаг
вэ? Өгөгдлийг далдлах ямар
ач холбогдолтой вэ? Бүх
өгөгдлийг нууц болох уу?
Яагаад вэ?
M.EC203* -- OOP (C++) -- Lecture 02 37
Exercise 2-3
2-3. Ангийн удамших шинж
гэж юу вэ? Удамшил ямар
онцлогтой вэ? Эх болон хүү
анги гэж юу вэ?
M.EC203* -- OOP (C++) -- Lecture 02 38
Exercise 2-4
2-4. Полиморфизм гэж юу вэ?
Энгийн жишээгээр тайлбарла.
M.EC203* -- OOP (C++) -- Lecture 02 39
Have you questions?
M.EC203* -- OOP (C++) -- Lecture 02 40
Summary
• Object Interactions
• A message
• Inheritance
• Polymorphism
• SDLC
M.EC203* -- OOP (C++) -- Lecture 02 41
End of…
Thank you for
ATTENTION