C # Design and its UML (reverse engineering)

Source: Internet
Author: User

Now summarize the use of the C # class keywords (virtual, abstract, override, new, sealed), and familiarize yourself with OOP ideas, using the UML Tools ea (Enterprise Architect 7.5) Establish its reverse engineering to generate its UML.

Abstract declares abstraction classes, abstract methods:

    • The class in which the abstract method resides must be an abstract class;
    • Abstract classes cannot be instantiated directly, and must be implemented by their derived classes;
    • An abstract method does not contain a method body and must be implemented by a derived class in an override manner;

The virtual tag method is a virtual method:

    • You can override this method with override in a derived class
    • Does not overwrite or can be called by an object
    • No method with this tag (and no other markup), overriding the original method with new

Abstract and Virtual: method overrides use the Override keyword, both the method in interface and the abstract method require implementation

Sealed keywords:

    • When applying the sealed modifier to a class, this modifier prevents other classes from inheriting from the class, similar to the final keyword in Java;

The following is the specific C # code:

Using system;using system.collections.generic;using system.linq;using system.text;namespace UserNameSpace{//<    summary>//enum sex///</summary> public enum Sex {Male = ' male ', Female = ' female '}//<summary>        struct Studentparams//</summary> public struct Studentparams {public int id;        public string name;        Public Sex sex;        public string grade;    public string major;            }///<summary>//interface///</summary> interface Ipeople {string Name {            Get        Set            } sex Sex {get;        Set            } short age {get;        Set           } void Eat ();    } interface Iteacher:ipeople {void Teach ();    } interface Istudent:ipeople {void Study ();      }///<summary>//abstract base class///</summary> abstract class People:ipeople {  private string name;        private sex sex;              private short age;            public string Name {get {return Name! = null? Name: "NA";                } set {if (Value! = "") {name = value;            }}} Public sex sex {get {return sex;            } set {value = sex;             }} public short age {get {return ' > 0? Age: (short) 0; } set {if (value >= 0) {age = Valu                E }}}///<summary>//Virtual///</summary> public virtual void E        At () {Console.WriteLine ("People eat.");  }//<summary>      Abstract method, which must be overridden by a derived class, people is abstract class///</summary> public abstract void Sleep ();        } class Teacher:people, Iteacher {//<summary>////overriding base class virtual method///</summary>        public override void Eat () {Console.WriteLine ("Teacher Eat.");            }///<summary>///overriding base class abstract method///</summary> public override void Sleep () {        Console.WriteLine ("Teacher sleep.");        } public void Teach () {Console.WriteLine ("Teacher Teach."); }} sealed class Master:teacher {protected void Manage () {}} class Student:peop        Le, istudent {studentparams param; <summary>///overriding base class virtual method///</summary> public override void Eat () {C Onsole.        WriteLine ("Student eat."); }///<summary>//rewrite the base class abstract method///</summary>        public override void Sleep () {Console.WriteLine ("Student sleep.");        } public void Study () {Console.WriteLine ("Student Study.");            }} class Program {static void Main (string[] args) {Teacher Teacher = new Teacher ();            Iteacher Itea = (iteacher) teacher; Itea.            Eat ();            Student stu = new Student ();            Istudent Istu = (istudent) Stu; Istu.            Eat ();        Console.readkey (); }    }}

Based on the code above, I used the UML tool EA to generate the "class diagram" in reverse, as follows:

  

C # Design and its UML (reverse engineering)

Related Article

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.