火龙果·整理 uml.org.cn 1.4面向对象领域中的基本概念T1T2) public class Animal Animal 日Fields protected bool IsSleeping; +isSleeping:bool 曰Methods public void Sleep(){} +Sleep:void +Eat:void public void Eat(){}} public class Lion Animal{ public void StalkPrey(){}} Elephant Lion 目Fields 田Eiad的 Lion adoptedLion new Lion(); Methods 曰Methods Properties +Stalkprey:void adoptedLion.StalkPrey(); Properties adoptedLion.Eat(); 27/336
27/336 1.4 面向对象领域中的基本概念(7/12) public class Animal { protected bool IsSleeping; public void Sleep() { } public void Eat() { } } public class Lion : Animal { public void StalkPrey() { } } ... Lion adoptedLion = new Lion(); adoptedLion.StalkPrey(); adoptedLion.Eat(); public class Animal { protected bool IsSleeping; public void Sleep() { } public void Eat() { } } public class Lion : Animal { public void StalkPrey() { } } ... Lion adoptedLion = new Lion(); adoptedLion.StalkPrey(); adoptedLion.Eat();
火龙果·整理 uml.org.cn 1.4面向对象领域中的基本概念8TZ 多态 Animal Method Behavior Object Elephant Eat ( Eat Grass Cat Eat() Eat Mouse Mouse Eat() Eat Cheese 28/336
28/336 1.4 面向对象领域中的基本概念(8/12) Animal Object Animal Object Elephant Cat Mouse Behavior Behavior Eat Grass Eat Mouse Eat Cheese Method Method Eat () Eat () Eat () • 多态
火龙果·整理 uml.org.cn 1.4面向对象领域中的基本概念T2) 多态 deer lion Case of animaltype: If animaltype=elephant then EatGrass(data); if animaltype=cat then EatMouse(data); if animaltype=mouse then EatCheese(data); end case; animaltype.eat(data); myAnimal.eat(data); 297336
29/336 1.4 面向对象领域中的基本概念(9/12) • 多态 Case of animaltype: If animaltype=elephant then EatGrass(data); if animaltype=cat then EatMouse (data); if animaltype=mouse then EatCheese (data); end case; animaltype.eat(data animaltype.eat(data); myAnimal.eat(data myAnimal.eat(data); deer lion
火龙果·整理 1.4面向对象领域中的基本概念10 uml.org.cn 消息 Sender object receiver object attributes: attributes: operations: operations: 301336
30/336 1.4 面向对象领域中的基本概念(10/12) • 消息 Sender object attributes: operations: receiver object attributes: ? operations:
火龙果·整理 uml.org.cn 1.4面向对象领域中的基本概念T2 ·消息(续1) message:destination,operation,parameters] Sender object attributes: receiver object attributes: operations: message:sender, operations: return value(s)] message:receiver,operation,parameters] 31/336
31/336 1.4 面向对象领域中的基本概念(11/12) • 消息 ( 续1) – message: [ destination, operation, parameters] Sender object attributes: operations: receiver object attributes: operations: message:[ receiver, operation, parameters] message:[ sender, return value(s) ]