30
Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to now Basic Concepts Object Properties of OOP Code Pieces Java Matlab What’s OOP languages C Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Introduction to Object Oriented Programming Kiwi Wang DISP March 21, 2014 Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 1 / 30

Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Embed Size (px)

Citation preview

Page 1: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

Introduction to Object OrientedProgramming

Kiwi Wang

DISP

March 21, 2014

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 1 / 30

Page 2: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

Outline

1 History

2 Basic Concepts

3 Code Pieces

4 Conclusion

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 2 / 30

Page 3: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

History

Outline

1 History

2 Basic Concepts

3 Code Pieces

4 Conclusion

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 3 / 30

Page 4: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

History Early Development

Simula 67

Working on simulations that deal with exploding ships.

They grouped the ships into different categories.

Each ship has its own class.

Each class would generate its unique behaviors anddata.

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 4 / 30

Page 5: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

History Early Development

Smalltalk

First use the term ”object oriented programming(OOP)”

First language to introduce the inheritance concept

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 5 / 30

Page 6: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

History From then to now

after 1980…

Object Oritented Programming has become prominent.

The most importancefactor is C++.

Also play a importance role in the development ofevent–driven programming(ex. GUI)

However, nowadays, when it comes to OOP, we meanOOP concepts combined with procedures that areuseful to programmers.

Explode out concepts of design patterns, dataabstraction…

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 6 / 30

Page 7: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

History From then to now

So, what’s OOP?

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 7 / 30

Page 8: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

Basic Concepts

Outline

1 History

2 Basic Concepts

3 Code Pieces

4 Conclusion

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 8 / 30

Page 9: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

Basic Concepts Object

Everything is an object…

Real–World: dogs, cats, computers…They all have states and behaviors.

Software Object: Mimic to Real–World objectsThey also have states and behaviors.

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 9 / 30

Page 10: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

Basic Concepts Properties of OOP

Three Basic Properties of OOP

EncapsulationClasses -> Interfaces -> design patterns…

Inheritance

PolymorphismMysterious one! Go details next page.

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 10 / 30

Page 11: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

Basic Concepts Properties of OOP

Polymorphism

The ability to appear in many forms.

The ability to process objects differently depending ontheir data type or class.

More specifically, it is the ability to redefine methods forderived classes.

Polymorphism is considered to be a requirement of anytrue OOP.

多種不同的子物件繼承同一種上層物件時,我們可以用上層

物件容納之,在呼叫時仍然會根據真實物件型態呼叫對應的

子物件函數。

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 11 / 30

Page 12: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

Basic Concepts Properties of OOP

Polymorphism – examples

Operator, such as + acts differently on integers,Strings, bits…Two basic ideas

Method Overriding: subclass, identical methodsignature.Dynamic binding: during run–time, actual methodexecuted is determined by type of objects, not type ofreference.

Allows superclass and subclass objects to be accessed ina regular, consistent way.(ex. draw different graphicalobjects in an array using the same draw function.)

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 12 / 30

Page 13: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

Code Pieces

Outline

1 History

2 Basic Concepts

3 Code Pieces

4 Conclusion

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 13 / 30

Page 14: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

Code Pieces Java

Encapsulation

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 14 / 30

Page 15: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

Code Pieces Java

Inheritance

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 15 / 30

Page 16: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

Code Pieces Java

Polymorphism

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 16 / 30

Page 17: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

Code Pieces Java

Result

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 17 / 30

Page 18: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

Code Pieces Matlab

Matlab supports OOP, too.

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 18 / 30

Page 19: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

Code Pieces Matlab

Matlab – main.m

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 19 / 30

Page 20: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

Code Pieces Matlab

Matlab – result

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 20 / 30

Page 21: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

Code Pieces What’s OOP languages

However…

By the term ”OOP–support language”, we mean thatit’s easier and straightforward to develop programsunder OOP concepts on that language.

It’s possible to develop an OOP–based program on anyprogramming language.

Actually, someone says that it’s really how OOP ispracticed in early time…

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 21 / 30

Page 22: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

Code Pieces C

Use C to demo three basic features of OOP

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 22 / 30

Page 23: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

Code Pieces C

Use C to demo three basic features of OOP –result

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 23 / 30

Page 24: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

Code Pieces C

Encapsulation

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 24 / 30

Page 25: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

Code Pieces C

Encapsulation – constructor

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 25 / 30

Page 26: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

Code Pieces C

Inheritance

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 26 / 30

Page 27: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

Code Pieces C

Inheritance – constructor

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 27 / 30

Page 28: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

Code Pieces C

Polymorphism – Use generic pointers but hard toremenber all pointer types that each functionneeds…

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 28 / 30

Page 29: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

Conclusion

Outline

1 History

2 Basic Concepts

3 Code Pieces

4 Conclusion

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 29 / 30

Page 30: Introduction to Object Oriented Programmingdisp.ee.ntu.edu.tw/class/20140321-OOP.pdf · Introduction to Object Oriented Programming Kiwi Wang History Early Development From then to

Introduction toObject Oriented

Programming

Kiwi Wang

History

Early Development

From then to now

Basic Concepts

Object

Properties of OOP

Code Pieces

Java

Matlab

What’s OOP languages

C

Conclusion

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

...

.

Conclusion

Usefulness and Debates

GUI, Android SDK, LLVM, gcc…Important benefits come with OOP:

maintainments, readability, productivity, and the reuseof codes.

However, there is no free lunch:There are debates about OOP, such as type safety,coding structures…

As a solid power to advance developments of software,it’s still worth to know about OOP.

Kiwi Wang (DISP) Introduction to Object Oriented Programming March 21, 2014 30 / 30