C # Design of OOP 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:

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceusernamespace{/// <summary>    ///Enumerate Sex/// </summary>     Public enumSex {Male ='male', Female ='female' }    /// <summary>    ///Structural Body Studentparams/// </summary>     Public structStudentparams { Public intID;  Public stringname;  Publicsex sex;  Public stringgrade;  Public stringMajor; }    /// <summary>    ///Interface/// </summary>    InterfaceIpeople {stringName {Get; Set; } Sex Sex {Get; Set; }         ShortAge {Get; Set; }        voidEat (); }    InterfaceIteacher:ipeople {voidTeach (); }    InterfaceIstudent:ipeople {voidStudy (); }    /// <summary>    ///abstract base class/// </summary>    Abstract classPeople:ipeople {Private stringname; Privatesex sex; Private  ShortAge ;  Public stringName {Get            {                returnName! =NULL? Name:"NA"; }            Set            {                if(Value! ="") {Name=value; }            }        }         Publicsex Sex {Get            {                returnsex; }            Set{Value=sex; }        }         Public  ShortAge {Get            {                returnAge >0? Age: ( Short)0; }            Set            {                if(Value >=0) { age=value; }            }        }        /// <summary>        ///virtual Method/// </summary>         Public Virtual voidEat () {Console.WriteLine ("people eat."); }        /// <summary>        ///abstract method, which must be overridden by a derived class, is people as an abstract class/// </summary>         Public Abstract voidSleep (); }    classTeacher:people, Iteacher {/// <summary>        ///overriding base class virtual methods/// </summary>         Public Override voidEat () {Console.WriteLine ("Teacher eat."); }        /// <summary>        ///overriding base class abstract methods/// </summary>         Public Override voidSleep () {Console.WriteLine ("Teacher sleep."); }         Public voidTeach () {Console.WriteLine ("Teacher teach."); }    }    Sealed classMaster:teacher {protected voidManage () {}}classStudent:people, istudent {studentparams param; /// <summary>        ///overriding base class virtual methods/// </summary>         Public Override voidEat () {Console.WriteLine ("Student eat."); }        /// <summary>        ///overriding base class abstract methods/// </summary>         Public Override voidSleep () {Console.WriteLine ("Student sleep."); }         Public voidStudy () {Console.WriteLine ("Student study."); }    }    classProgram {Static voidMain (string[] args) {Teacher Teacher=NewTeacher (); Iteacher Itea=(iteacher) teacher; Itea.            Eat (); Student Stu=NewStudent (); 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 of OOP 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.