28
King Mongkut’s University of Technology North Bang Faculty of Information Technology ON THE TECHNOLOGICAL FRONTIER WITH ANALYTICAL MIND AND PRACTICE Object-Oriented Concept 1

Object-Oriented Concept

  • Upload
    gaenor

  • View
    90

  • Download
    0

Embed Size (px)

DESCRIPTION

Object-Oriented Concept. Content. Object-Oriented Concept Class & Object Object-Oriented Characteristics How does it work? Relationships Between Classes Development Tools Advantage / Disadvantage. Object-Oriented Concept. Originated in 1970s. Imitation of things in the real world. - PowerPoint PPT Presentation

Citation preview

Page 1: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

ON THE TECHNOLOGICAL FRONTIER WITH ANALYTICAL MIND AND PRACTICE

Object-Oriented Concept

1

Page 2: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

2

Object-Oriented ConceptClass & ObjectObject-Oriented CharacteristicsHow does it work?Relationships Between ClassesDevelopment ToolsAdvantage / Disadvantage

Content

Page 3: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

3

Originated in 1970s.Imitation of things in the real world.Interactions between objects form a task.

Object-Oriented Concept

Page 4: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

4

Class is a template of objects of a same kind or type.PersonMovieUniversity

Object is an instantiation of class.Leonardo da VinciThe HobbitKMUTNB

Many objects of the same class have the same set of attributes and behavior but their values may vary.

Class & Object

Page 5: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

5

Class contains:Class name.Attributes or data of that class. Type of each attribute

should be specified.Methods (operations / functions) or what that class can do

or the behavior of that class.

Class

Page 6: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

6

Class Notation

Name

Attributes

Methods

Compartments

Class name

Data stored in the class

What this class can do

Page 7: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

7

ExampleClass University

University

NameLocationFacultiesNo. of Student…

openclose

Instantiate

Objects of Class UniversityUniversity

KMUTNBBKK{IT, …}5347…

openclose

University

University

Page 8: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

8

class University {String uName;String location;Collection faculties;int numberOfStudent;…public void open() {…}public void close() {…}

}

Class as Programming Code

Page 9: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

9

What are you interested in?Both concrete and abstract.Is it just a value? - attributeOr is it composed of a group of data?Similar to identifying Entities in ERD.

What should be a class/object?

Page 10: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

10

EncapsulationInheritancePolymorphism

Object-Oriented Characteristics

Page 11: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

11

Data are hidden within object.Methods are included in the object.Communication with the object is through methods (interface)In OOP, class usually has setters and getters methodsE.g. from University

public void setUniversityName(String newName) {uName = newName;

}public String getUniversityName() {

return uName;}

Encapsulation

Page 12: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

12

Three levels of visibilityPublic – Visible to allPrivate – Visible to that class onlyProtected – Visible to that class and its subclasses

Unspecified (Java only) – Visible to all within the same package or folder (not recommended, especially in large-scale program)

Visibility

Page 13: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

13

A class formed by inheriting the attributes and behavior of another class.

Class A inherits from Class BClass A is a subclass of the parent class B.Class B is a parent class of the subclass A.Can a class inherit from 2 parent classes?

Subclass / Derived ClassParent Class / Base Class / Superclass

Inheritance

Page 14: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

14

Class Hierarchy ExampleTransport

AirlinerShipVehicle

Car Truck MotorcycleTrain

Steam-Powered Electric Diesel Maglev

Spacecraft

Page 15: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

15

SportsWeaponsGamesAnimalsFoodDrink

More Examples

Page 16: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

16

Subclass initially has the same attributes and methods as its parent class.

Subclass can alter or override the inherited attributes and methods.

Subclass can add new attributes and methods.How is inheritance useful?Help reuse source code – how?

Inheritance

Page 17: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

17

Subclass can be passed as argument for method that specifies its parent class as parameter

But not the other way around!Why?How useful?

Implication of Inheritance in Object-Oriented Programming

Page 18: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

18

Method OverridingA method in a subclass with the same name, parameter set,

and return type as the method in its parent class.Method Overloading

A method in a class with the same name and return type but different parameter set as a method in the same class or its parent class.public void getName() {…}public void getName(String type) {…}public void getName(int type) {…}

Method Overriding and Overloading

Page 19: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

19

Poly = Many, Morph = FormInvoking a method name may give different action and/or

result depending on the kinds of objects.What would you do when you are told to “Find one

million Baht” ?“Play your favorite sport”?

Polymorphism

Page 20: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

20

How do mammals reproduce? Human, Dogs, Cats, … etc.What about platypus?

See Transport example again

Referred to method overriding

Polymorphism

Page 21: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

21

Association – uses, other common verbsAggregation – is inComposition – is part ofInheritance / Generalization – is a

See UML for correct notation.

Relationships Between Classes

Page 22: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

22

You need to know what each object can do (methods) and how to use them.

You don’t need to know the detail of the methods.Tell the object to do something by calling its methods

and give proper parameters.A task is form by interactions among objects.Imitation of the real world activities.Parameter vs Argument

How does it work?

Page 23: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

23

LogicallyStudent tells the librarian who he/she is.Student tells the librarian which books he/she wants to

borrow.The librarian records the loan.The librarian tells the student by which date he must return

the books.

Example : Borrow books

Page 24: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

24

Order a flower for your friend in England.Buy 2 movie tickets.Make a withdrawal from your bank account.Travel by Skytrain.

More Scenarios

Page 25: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

25

Unified Modeling Language (UML)Specification by Object Management Group (OMG)

www.omg.orgConsist of 9 diagrams to explain a system.

Rational RoseObject-Oriented software development tool utilizing UML.Provide source code generation.

Microsoft Visio

Development Tools

Page 26: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

26

JavaCross-platformJava Virtual Machine

C++C#…

OO Programming Language

http://en.wikipedia.org/wiki/List_of_object-oriented_programming_languages

Page 27: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

27

Support source code reuse.Faster development time.Both data and operation aspects are combined.Object-Oriented software are easier to maintain.

Low dependency between objects.An object can be replaced easily with minimum

modification to other objects.

Advantages

Page 28: Object-Oriented Concept

King Mongkut’s University of Technology North BangkokFaculty of Information Technology

28

Hard to understand for beginner and even some experienced programmers.

Object-Oriented programming requires more computation power (no longer matters)

Anything else?

Disadvantages