Person
|
+
name: string
+
sex: char
-
age: int
|
+
Work(in type: string): void
+
Person(in name: string, in sex: char, in age: int): void
+
Speak(): void
+
Eat(): void
|
mary: Person
|
name: string
=
"Mary"
sex: char
=
'F'
age: int
=
24
|
內幕:UML與源代碼
UML是一種設計語言,它的目的不是表現細節,而是表現結構,僅僅展現必要的細節。所以,UML不可能與源代碼一一對應,只存在結構上的對應關係。做爲一種參考,下面列出了圖6-7中的類圖的C#源代碼:
interface IHuman
{
}
class Person : IHuman
{
void Read(Book book)
{
// …
}
}
class Author : Person
{
public Book[] books;
}
class Book
{
public Author author;
public Page[] pages;
}
class Page
{
}
class Bookshelf
{
public Book[] books;
}
|