6.#class,#oop# august18,#2015#
TRANSCRIPT
![Page 1: 6.#Class,#OOP# August18,#2015#](https://reader031.vdocuments.net/reader031/viewer/2022013005/61cc838ca247f01f6047954d/html5/thumbnails/1.jpg)
6. Class, OOP August 18, 2015
Minhaeng Lee
IEDU Programming AcBvity, Summer, 2015
![Page 2: 6.#Class,#OOP# August18,#2015#](https://reader031.vdocuments.net/reader031/viewer/2022013005/61cc838ca247f01f6047954d/html5/thumbnails/2.jpg)
FOP and OOP • FuncBon Oriented Programming
– FuncBon call from main – Main – funcBon – main – funcBon … – Difficult to management – To replace funcBon, we need to edit file itself – Pure C style. Nowadays, not popular.
• Object Oriented Programming – Object call from main – Main – object – method – object – main … – Easier to management – To replace class, we need to change file (class) – SBll popular in Java, C++, python, javascript, ….
![Page 3: 6.#Class,#OOP# August18,#2015#](https://reader031.vdocuments.net/reader031/viewer/2022013005/61cc838ca247f01f6047954d/html5/thumbnails/3.jpg)
FuncBon Oriented Programming
return
main
funcBon
funcBon
returns
calls
1 2
3 4
Class
Class concept doesn’t have any big
meaning
![Page 4: 6.#Class,#OOP# August18,#2015#](https://reader031.vdocuments.net/reader031/viewer/2022013005/61cc838ca247f01f6047954d/html5/thumbnails/4.jpg)
Object Oriented Programming
main
funcBon
returns
calls
1 2
3 4
Class A
return
Public FuncBon
Private funcBon
Private funcBon
returns
calls
1 2
3 4
Class B
Instance of Class B
Interface
![Page 5: 6.#Class,#OOP# August18,#2015#](https://reader031.vdocuments.net/reader031/viewer/2022013005/61cc838ca247f01f6047954d/html5/thumbnails/5.jpg)
Class • Consist of
– Variables • Variables declared in class (but outside of method)
– Methods • Similar meaning with funcBon. We use both
– Constructor • A Method called when a class is iniBalized (=allocated to memory by new keyword)
• Instance? – The class variable made by new keyword – Memory allocated class variable – Example
• a is an instance • MyClass a = new MyClass();
• Inheritance (today) • Polymorphism (next week)
![Page 6: 6.#Class,#OOP# August18,#2015#](https://reader031.vdocuments.net/reader031/viewer/2022013005/61cc838ca247f01f6047954d/html5/thumbnails/6.jpg)
Constructor
• A method called at memory allocaBon • IniBalizaBon process involved – Has class name as its name – Similar to funcBon but without return type – public <className> (<parameters>) { }
• Default constructor is defined already – public <className>() { }
![Page 7: 6.#Class,#OOP# August18,#2015#](https://reader031.vdocuments.net/reader031/viewer/2022013005/61cc838ca247f01f6047954d/html5/thumbnails/7.jpg)
Circle.java
ClassTest.java
![Page 8: 6.#Class,#OOP# August18,#2015#](https://reader031.vdocuments.net/reader031/viewer/2022013005/61cc838ca247f01f6047954d/html5/thumbnails/8.jpg)
Access Specifier • Public – Allow to everybody – Outside of class to local variables/methods
• private (default) – Allow to class itself – Inside of class to its local variables/methods
• Protected – Allow to its descent – Inside of descent (children inherit itself) to class itself
![Page 9: 6.#Class,#OOP# August18,#2015#](https://reader031.vdocuments.net/reader031/viewer/2022013005/61cc838ca247f01f6047954d/html5/thumbnails/9.jpg)
extends keyword for inheritance
hdp://www.tutorialspoint.com/java/java_inheritance.htm
• Sub has all properBes (variables and methods) of Super
• When? • Divide file (or class) based
on their role • Make common variables or
methods of Sub into Super
![Page 10: 6.#Class,#OOP# August18,#2015#](https://reader031.vdocuments.net/reader031/viewer/2022013005/61cc838ca247f01f6047954d/html5/thumbnails/10.jpg)
extends keyword for inheritance
hdp://www.tutorialspoint.com/java/java_inheritance.htm
![Page 11: 6.#Class,#OOP# August18,#2015#](https://reader031.vdocuments.net/reader031/viewer/2022013005/61cc838ca247f01f6047954d/html5/thumbnails/11.jpg)
extends keyword for inheritance
hdp://www.tutorialspoint.com/java/java_inheritance.htm
![Page 12: 6.#Class,#OOP# August18,#2015#](https://reader031.vdocuments.net/reader031/viewer/2022013005/61cc838ca247f01f6047954d/html5/thumbnails/12.jpg)
Senior Programmer Team Members
PracBce : Programmer Company
Programmer Computer ID
Employee
Name Age
![Page 13: 6.#Class,#OOP# August18,#2015#](https://reader031.vdocuments.net/reader031/viewer/2022013005/61cc838ca247f01f6047954d/html5/thumbnails/13.jpg)
Employee.java
![Page 14: 6.#Class,#OOP# August18,#2015#](https://reader031.vdocuments.net/reader031/viewer/2022013005/61cc838ca247f01f6047954d/html5/thumbnails/14.jpg)
Programmer.java
![Page 15: 6.#Class,#OOP# August18,#2015#](https://reader031.vdocuments.net/reader031/viewer/2022013005/61cc838ca247f01f6047954d/html5/thumbnails/15.jpg)
SeniorProgrammer.java
![Page 16: 6.#Class,#OOP# August18,#2015#](https://reader031.vdocuments.net/reader031/viewer/2022013005/61cc838ca247f01f6047954d/html5/thumbnails/16.jpg)
Company.java (to contain main)
![Page 17: 6.#Class,#OOP# August18,#2015#](https://reader031.vdocuments.net/reader031/viewer/2022013005/61cc838ca247f01f6047954d/html5/thumbnails/17.jpg)
Data Structure : preview
• Stack • Linked list • Tree • HashMap
![Page 18: 6.#Class,#OOP# August18,#2015#](https://reader031.vdocuments.net/reader031/viewer/2022013005/61cc838ca247f01f6047954d/html5/thumbnails/18.jpg)
QuesBons
![Page 19: 6.#Class,#OOP# August18,#2015#](https://reader031.vdocuments.net/reader031/viewer/2022013005/61cc838ca247f01f6047954d/html5/thumbnails/19.jpg)
References
• IBM – hdp://www.ibm.com/developerworks/java/tutorials/j-‐introtojava1/j-‐introtojava1-‐pdf.pdf