UML Learning: The dependency relationship of Class diagram classes

Source: Internet
Author: User

The concepts and symbols of dependency relations

dependencies represent a class that relies on other classes in some way. When two classes are in a dependency relationship, the change of one of the classes may affect another class.

Symbol:

The performance of dependencies in code

In program code, a dependency means that an object of one class appears in the operation of another class. There are two common scenarios in which a class takes an object of another class as an argument for an action of its own (a formal parameter) or a local variable of an operation.

Program Demo: Code/train

Class train
    {public
        string number;
    
        Public train (String num)
        {number
            = num;
        }
    
        public void Run ()
        {
            Console.WriteLine ("Train start ...) Train arrives ");
        }
    
Train
 class Person {public string name;
        Public person (string name) {this.name=name; public void gotobeijing (train mytrain)//from Henan to Beijing {Console.Write (name+ "Go to Beijing to ride {0} train:", MyTrain.
            number);
        Mytrain.run (); 
            public void Gotohenan ()//from Beijing to Henan {train mytrain = new Train ("1488");
            Console.Write (name + "Go to Henan ride {0} train:", Mytrain.number);
        Mytrain.run (); } person 
Class program
    {
        static void Main (string[] args)
        {person
            person1 = new Person ("John");
            Person Person2 = new Person ("Dick");
    
            Train train1 = new Train ("1487 times"); Henan to Beijing
        train train2 = new Train ("1488 times");//Henan to Beijing
        Person1. Gotobeijing (train1);
            Person2. Gotobeijing (train2);
            Person1. Gotohenan ();
            Person2. Gotohenan ();
        }
    
Program

The corresponding class diagram:

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/project/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.