Object-Oriented Programming Concepts Tel: 02-824-5768 E-mail: hhcho@selabsoongsilackr? OOP (Object) (Encapsulation) (Message) (Class) (Inheritance) (Polymorphism) (Abstract Class) (Interface) 2 1
+ = (Dependency) int main( ) { f0( ); f1( ); f2( ); f3( ); f4( ); f5( ); f999( ); 3 + = + = f3( ); f5( ); f2( ); f4( ); f7( ); f1( ); f6( ); 4 2
#1,,,, point, line, polygon, rectangle, square, ellipse, circle, window, etc person, student, faculty, staff, part-timer, etc character, word, sentense, paragraph, documents, fonts, etc 5 #2 ( ) (State) (Behavior) (Identity) 6 3
! 7 Java class point { int xposition; int yposition; boolean status; colortype color; public: void move (int x, int y); void setcolor (colortype c); void penup ( ); void pendown ( ); 8 4
, (Blackbox) 9 Java class point { int xposition; int yposition; boolean status; colortype color; public: void move (int x, int y); void setcolor (colortype c); void penup ( ); void pendown ( ); move (int, int); setcolor (colortype ); penup ( ); pendown ( ); 10 5
,, Arguments <receiver> <operation_name> <arguments> mypoint move (10, 2); mypoint setcolor (blue); Receiver Arguments Sender 11 Bob, Person, (Specification) 12 6
Java [ ] class { public abstract final (abstract method) 13 class Employee { String name; String title; String dept; int salary; // public: void promote (String newtitle); void changedept(string newdept); void changesalary (int newsalary); // ; 14 7
(Instance) (Instance) class Employee { char* name; // ; Employee Kim; Employee Park; 15 (Object Reference); Employee Kim; Employee Park; Kim = new Employee(); Employee Kim = new Employee() & 16 8
Employee Kim = new Employee(); Employee Park = new Employee(); Kim Kimpromote( ); KimchangeDept( ); title ParkchangeSalary(3500); name dept Park name title dept salary 4500 salary 3000 17 (Garbage Collector) finalize() void finalize() { 18 9
Java (Attribute), class Point { // field int xposition; int yposition; // method void move(int x, int y); 19 ( ) private protected public package package 20 10
( ) private package protected public O O O O X X X X O X O O X O O O 21 (Superclass, Base class) (Subclass, Derived class, Extended class) (Class Inheritance Hierarchy) 22 11
class identifier extends Superclass { class ; Java Object 23 class Person { String name; String address: void changeaddress (String newaddress); void printlabel (int copies = 1); class Student extendsperson { deptcode major, minor; float GPA; int coursestaken; void printtranscript (int copies = 1); 24 12
,,( ) move(int x, int y); print( ); for Polygon and Circle for TextFile, GraphicFile and WordProcessorFile ( ) class printer { public: void print( ); void print(int n); // prints 1 copy // prints n copies 25 vs (Overriding) ( ) (Overroading) ( ) 26 13
: Print( ) Text files Word processor files Graphics files, print( ) Polymorphic print( ) Text File int print( ); File WP File int print( ); filename, filesize, virtual int print( ) = 0; Graphic File int print( ); 27 class DataRenderer { void draw(string s) { void draw(int i) { void draw(float f) { 28 14
(Abstract Class) (Property) ( ) abstractclass Number { (Concrete Class),, 29 Figure ClosedFigure Point OpenFigure Ellipse Polygon Arc Segment Circle Triangle Rectangle Line Square 30 15
colortype fillcolor; void setfillcolor(colortype c); virtual void fillfigure( ) = 0; float cx, xy; Ellipse ClosedFigure Polygon Figure Point int x, y; void move(int xx, int yy); Point* points; void move(int xx, int yy); float getperimeter( ); colortype color; int linewidth; void setcolor(colortype c): color(c) {; virtual void move(int xx, int yy) = 0; virtual float getperimeter( ) = 0; Arc OpenFigure Segment Circle void move(int xx, int yy); float getperimeter( ); Triangle Rectangle Square void move(int xx, int yy); float getperimeter( ); int length; void move(int xx, int yy); float getperimeter( ); Line 31 (1) + prototype interface { 32 16
(2) // Aquatic interface interface Aquatic { public void swim( ); public void breathunderwater( ); // Aquatic interface Mermaid class class Mermaid extends Human implements Aquatic { // public void swim( ) { // public void breathunderwater( ) { // 33 (1) ( ) package ; (import) import ; 34 17
(2) hyunhoontest PackageTest, 1 hyunhoon\test 2 hyunhoon\test PackageTestjava package hyunhoontest; class PackageTest { // 3 Compile \hyunhoon\test\javac PackageTestjava 4 \java hyunhoontestpackagetest 35 javalang javaio javautil javanet javaapplet AWT javaawt AWT javaawtimage AWT Peer javaawtpeer 36 18
,, (Object) (Class) (Inheritance) 37 19