Date post: | 12-Jan-2016 |
Category: |
Documents |
Upload: | earl-caldwell |
View: | 216 times |
Download: | 1 times |
IS0514 Slide 1
IS0514 Lecture Week 5
Introduction to Object Orientation
IS0514 Slide 2
Why Object Oriented?• Based on domain analysis / subject matter analysis• Close match to real world• Nearly all Modern Technologies are Object Oriented
– Java / C# / C++ / PHP (object extension) / Delphi– Oracle – Object relational database– => closer match to end solution
• Widely accepted ( most common approach )• Extensible / Maintainable• Reusable
IS0514 Slide 3
Today's Lecture
• Introduction to object orientation concepts– Object
– Class
– Method
– Attribute
– Relationships
• Inheritance
IS0514 Slide 4
What is the world?
• The world can be seen to consist:– Things
– Relationships between things
• A thing can be:– Physical / Tangible
– Idea / Concept / Non-Tangible
• In object orientation a thing is called an Object• “Thing-Oriented Analysis!”
IS0514 Slide 5
Exercise 1
Think about the objects in this room.• Try to identify the objects in this room
– What “things” are here• Physical• Conceptual / Ideas
• In groups of 3-4 spend 5 minutes discussing what objects there are. At the end of that time you will be asked to share your thoughts with the rest of the class.
IS0514 Slide 6
Exercise 1 - Possible Objects
Physical • The lecturer• Each of the students• Each of the seats• The handouts• Computer• Projector• Crisps / Chocolate / Cans• Each of the Mobile phone
– switched off or silent!
Ideas• The lecture itself• Exercise 1• Lecture slide
IS0514 Slide 7
Attributes and behaviour
• Objects have properties called attributes– Attributes are the data associated
with an object
• Objects have behaviour – we call these methods – These are the tasks an object will
do (typically when we ask it to)
– These may also be called operations / member functions but we will try and call them methods
• Example – A Car– Attributes
• Make• Model• Engine Size• Current Speed
– Methods• break()• accelerate()• changeGear()• honkHorn()
IS0514 Slide 8
Exercise 2
• Think about the object “a student”• Try an identify its
– Attributes– Methods
• Think about which of these are relevant as regard to the university?
• In groups of 3-4 spend 5 minutes discussing this. At the end of that time you will be asked to share your thoughts with the rest of the class.
IS0514 Slide 9
Exercise 2 - Solution
Attributes
• Name
• Registration Number
• Date of Birth
• Gender
• Address
• Programme
• etc
Methods
• AttendLecture()
• AttendSeminar()
• CompleteAssignment()
• SitExam()
• etc
IS0514 Slide 10
Categories of things• Things naturally fall into categories (Car, Furniture, House)• In object orientation, a category of things is called a class
– an object is an instance of a class – my car => object Car => class
• Objects share behaviour as defined by their class – respond to the same set of methods– For example all cars can accelerate– Some value(s) can affect what a method does
• Objects share Class attributes e.g. every car has a colour• Object attributes will have different values
IS0514 Slide 11
Exercise 3
Think about the objects in the room and try to identify what classes these objects belong to.
• In groups of 3-4 spend 5 minutes discussing this. At the end of that time you will be asked to share your thoughts with the rest of the class.
IS0514 Slide 12
Exercise 3 - Possible Classes
Physical
• Person
• Lecturer
• Student
• Seat
• Furniture
• Handout
• Computer
• Projector
Ideas
• Lecture
• Exercise
IS0514 Slide 13
Classes and Objects –more formally
• Class – Template to define specific instances or objects
• Object – Instantiation of a class• Attributes – Describes each object• Behaviors – Specify what each object can do
– Methods (a.k.a. operations)
IS0514 Slide 14
Classes and Objects
IS0514 Slide 15
Methods and Messages
• Methods implement objects’ behavior– Analogous to a function or procedure
• Messages are sent to trigger methods– Procedure call from one object to another object
IS0514 Slide 16
Messages and Methods
IS0514 Slide 17
Relationships between Classes
• Classes / Objects can be related– Student completes Assignment
– Student is registered for a Module
– Student has access to the Blackboard
• Some relationships are stronger than others– Student is a kind of Person
– Lecturer is a kind of Person
• Inheritance– Is a generalisation / specialisation relationship between two classes
– Is “a kind of” relationship
IS0514 Slide 18
Class Hierarchy
IS0514 Slide 19
Exercise 4
Think about the class hierarchy between Person, Student, Lecturer, Full Time Student and Part Time Student.
• Draw the class hierarchy • In groups of 3-4 spend 5 minutes discussing this. At
the end of that time you will be asked to share your thoughts with the rest of the class.
IS0514 Slide 20
Exercise 4 - Class Hierarchy
Person
Lecturer Student
PartTimeStudent FullTimeStudent
IS0514 Slide 21
Inheritance – some terms
• Superclasses or general classes are at the top of a hierarchy of classes
• Subclasses or specific classes are at the bottom• Subclasses inherit attributes and methods from
classes higher in the hierarchy• In our tree, which are the subclasses and
superclasses?
IS0514 Slide 22
Inheritance
IS0514 Slide 23
Basic Characteristics of Object Oriented Systems
• Classes and Objects• Methods / Messages• Inheritance• THE BASICS OF OBJECT ORIENTATION
• Next Week: Class Diagrams
IS0514 Slide 24
This weeks reading
ESSENTIAL READING
Dennis A, Wixom B, and Tegarden D (2005) System Analysis and Design with UML version 2 second edition, Wiley
Pages 23-29
Further reading
Bennett, S., McRobb, S. and Farmer, R. (2002) Object-Oriented Systems Analysis and Design using UML, 2nd Edition, McGraw-Hill
Chapter 4