• Save
oop presentation note
Upcoming SlideShare
Loading in...5
×
 

oop presentation note

on

  • 645 views

 

Statistics

Views

Total Views
645
Views on SlideShare
645
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

oop presentation note oop presentation note Presentation Transcript

  • คุณชื่ออะไร aliceเมื่อวานคุณไปกับใคร
  • behavior behaviorbehavior behavior data message data behavior behavior
  • ● CLASS นิยามของวัตถุใดวัตถุหนึ่งหรือกลุ่มของ วัตถุ ที่มีคุณลักษณะและพฤติกรรมเหมือนกัน● วัตถุ object ● จับต้องได้ (คำานาม) ● จับต้องไม่ได้ (การดำาเนินการหรือกระบวนการ)● domain
  • Class Diagram class Person { Person } public class Person { +Person } public class Person { +Person // property private String name; -name:String } public class Person { +Person private String name; private int age; -name : String } -age : int
  • Class Diagram public class Person { private String name; +Person private int age; -name : String public String getName(){ -age : int return this.name; } +getName() : String+setName(String) : void public void setName(String name){ +getAge() : int This.name = name; +setAge(int) : void } public int getAge(){ return this.age; } public void setAge(int age){ this.age = age; } }
  • int x; +Personx = 10; 10 -name : String -age : int X +getName() : String +setName(String) : void 10 +getAge() : int +setAge(int) : void intPerson p; @AB12345FHp = new Person(); Name:String p age:int @AB12345FH Person
  • Person a;a = new Person();Person b;b = a; a @AB12345FH Copy Person b @AB12345FH Replace @AB12345FH Person
  • @AB12345FHPerson p;p = new Person(); Name:String age:int p @AB12345FHPerson a; Persona = new Person(); @AB15689FH a Name:String age:int @AB15689FH Person
  • 0 Calculator 7 8 9 + -digit:double 4 5 6 - +getDigit():double 1 2 3 x +setDigit(double):void +digitPressed(String):void . 0 = /+operationPressed(String):void
  • 0 3+5 = ? cal : Calculator 7 8 9 + 4 5 6 - setDigit(0) 1 2 3 x digitPressed(“3”) . 0 = / operationPressed(“+”) digitPressed(“5”) Calculator operationPressed(“=”) -digit:double getDigit() +getDigit():double +setDigit(double):void +digitPressed(String):void+operationPressed(String):void
  • +Person digit 3 3 oldDigit operator 0 30 + 30 30 + 5 5 = 35 35 + 30 + 5
  • Calculator Tester
  • Model View Controller CalculatorView ViewCalculatorController Calculator Controller Model
  • CalculatorView lblDigit btnDigit7 btnOperationAdd btnOperationSubtract btnOperationMultiply btnOperationDot btnOperationDivide btnDigit0 btnOperationEqual
  • 01: public class CalculatorController { CalculatorController 02: 03: private Calculator model; -model:Calculator 04: private CalculatorView view; -view:CalculatorView 05: 06: public void setModel(Calculator model) { +setModel(Calculator):void 07: this.model = model;+setView(CalculatorView):void 08: } +digitPressed(String):void 09:+operationPressed(String):void 10: public void setView(CalculatorView view) { 11: this.view = view; 12: } 13: Calculator 14: public void digitPressed(String digit){ 15: 16: -digit:double 17: } 18: public void operationPressed(String operation){ 19: +getDigit():double 20: +setDigit(double):void 21: } +digitPressed(String):void 22: }+operationPressed(String):void
  •    : 21:     Calculator model; 22:     CalculatorController controler; 23:  24:     public CalculatorView() { 25:         model = new Calculator(); 26:         controler = new CalculatorController(); 27:         controler.setModel(model); 28:         controler.setView(this); 29:         initComponents(); 30:         model.setDigit(0); 31:         updateView(); 32:     } 33:  34:     public void updateView() { 35:         lblDigit.setText(Double.toString(model.getDigit())); 36:     }   :
  •    :319: private void btnDigit1ActionPerformed(java.awt.event.ActionEvent ev320:     // TODO add your handling code here:321:     controler.digitPressed(btnDigit1.getText());322: }   :324: private void btnOperationEqualActionPerformed(java.awt.event.Action325:     // TODO add your handling code here:326:     controler.operationPressed(btnOperationEqual.getText());327: }
  • 01: public class CalculatorController {02: 03:     private Calculator model;04:     private CalculatorView view;05: 06:     public void setModel(Calculator model) {07:         this.model = model;08:     }09: 10:     public void setView(CalculatorView view) {11:         this.view = view;12:     }13: 14:     public void digitPressed(String digit){15:         model.digitPressed(digit);16:         view.updateView();17:     }18:     public void operationPressed(String operation){19:         model.operationPressed(operation);20:         view.updateView();21:     }22: }
  • Array of ObjectArrayList
  • BankAccountList BankAccount BankAccount BankAccount BankAccountBankAccountList acl = new BankAccountList();Customer alice = new Customer(“Alice”, “123456”); BankAccountListBankAccount acc1 = new BankAccount(alice, 500); -accountlist:ArrayListacl.add(acc1); +add(BankAccount):void +get(int):BankAccountCustomer bob = new Customer(“Bob”, “123789”);BankAccount acc2 = new BankAccount(bob, 500);acl.add(acc1);BankAccount ba = acl.get(0);System.out.println(ba.holder.getName()); // Alice
  • PersonCustomer Employee