Upcoming SlideShare
×

# oop presentation note

524 views

Published on

Published in: Education
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
524
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
0
0
Likes
0
Embeds 0
No embeds

No notes for slide

### oop presentation note

1. 1. คุณชื่ออะไร aliceเมื่อวานคุณไปกับใคร
2. 2. behavior behaviorbehavior behavior data message data behavior behavior
3. 3. ● CLASS นิยามของวัตถุใดวัตถุหนึ่งหรือกลุ่มของ วัตถุ ที่มีคุณลักษณะและพฤติกรรมเหมือนกัน● วัตถุ object ● จับต้องได้ (คำานาม) ● จับต้องไม่ได้ (การดำาเนินการหรือกระบวนการ)● domain
4. 4. 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
5. 5. 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; } }
6. 6. 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
7. 7. Person a;a = new Person();Person b;b = a; a @AB12345FH Copy Person b @AB12345FH Replace @AB12345FH Person
8. 8. @AB12345FHPerson p;p = new Person(); Name:String age:int p @AB12345FHPerson a; Persona = new Person(); @AB15689FH a Name:String age:int @AB15689FH Person
9. 9. 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
10. 10. 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
11. 11. +Person digit 3 3 oldDigit operator 0 30 + 30 30 + 5 5 = 35 35 + 30 + 5
12. 12. Calculator Tester
13. 13. Model View Controller CalculatorView ViewCalculatorController Calculator Controller Model
14. 14. CalculatorView lblDigit btnDigit7 btnOperationAdd btnOperationSubtract btnOperationMultiply btnOperationDot btnOperationDivide btnDigit0 btnOperationEqual
15. 15. 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
16. 16.    : 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:     }   :
17. 17.    :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: }
18. 18. 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: }
19. 19. Array of ObjectArrayList
20. 20. 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
21. 21. PersonCustomer Employee