UML for .NET Developers ( Part 1)

Hôm nay ngồi rỗi rãi ôn lại chút kiến thức về UML, quyết định Post nội dung qua lên Blog cho đỡ quên.

Thôi, tiếng Việt chỉ thế thôi nhỉ, lập trình là phải Tiếng Anh cho nó PZỒ :D

1. Classes

C# Code UML

 

class Account
{

}


Account

 

2. Attributes

[visibility] [/] attribute_name[multiplicity] [: type [= default_value]]

C# Code UML

 

class Account
{

  private float balance =0;

  private float limit;

}


Account

- balance: float= 0

- limit: float;

 

3. Operations

[visibility] op_name([[in|out] parameter : type[, more params]])[: return_type]

C# Code UML

 

class Account 
   { 
   private float balance = 0; 
   private float limit;

   public void Deposite(float amount)
        {
            balance += amount;
        } 
   public void Withdraw(float amount)
        {
            balance -= amount;
        }
    }


Account

- balance: float= 0

- limit: float;

+ Deposite(amount: float)

+ Withdrwa(amount: float)

 

4. Visibility

Please note the follwing rules:

-

C# Code UML

 

class Account
    {
        private float balance = 0;
        public float limit;
        protected int id;
        internal int databaseId;

  public void Deposit(float amount)
        { 
         balance = balance + amount;
        } 
  private void Withdraw(float amount)
        { 
         balance = balance - amount;
        }
        protected int GetId()
        {
            return id;
        }
        internal int GetDatabaseId()
        {
            return databaseId;
        }

    }


Account

- balance: float= 0

+ limit: float;

# id: int;

~ databaseId: int

 

+ Deposite(amount: float)

- Withdrwa(amount: float)

# GetId(): int

~ GetDatabaseId() : int

 

5. Class & Instance

Operations and attributes that are static shoud have underline in the UML description.

# Code UML

 

class Person
    {
        private static int numberOfPeople = 0;
        private string name;
        private Person(string name)
        {
            this.name = name;
            numberOfPeople++;
        }
        public static Person CreatePerson(string name)
        {
            return new Person(name);
        }
        public string GetName()
        {
            return this.name;
        }
        public static int GetNumberOfPeople()
        {
            return numberOfPeople;
        }
    }


Person

- numberOfPeople: int= 0

- name: string

+ CreatePerson(name: string) : Person

+ GetName() : string

+ GetNumberOfPeople(): int

- Person(name: string)

Comments

Popular posts from this blog

Setup SharePoint 2010

Register CSS to SP Master Page