. C #-objects, classes, interfaces, inheritance, polymorphism

Source: Internet
Author: User

UML (Unified Modeling Language), Unified Modeling Language to study classes and objects

Object: Class Name

Myprinter:printer

+instant:bool Accessibility : member Name: type of member

Object: the component part of the OPP application . including data and operations, classes are instances of

properties of the object / Field :  data is used by attributes for outside code <string>. Length

methods of the object :  actions can be used by methods for outside code <string>. ToUpper ()

class : The type definition of an instantiated object

Class members include: Properties and Methods

Life cycle of an object :

construction phase: The time when an object was initially instantiated , which is done by the constructor function. calling constructors with the new keyword

Cupofcoffee Mycup = new Cupofcoffee (); default constructor to create an object

Cupofcoffee Mycup = new Cupofcoffee ("Blue Mountain");// non-default constructors to create objects

Run phase: In the state being used.

destructor phase: The cleanup work to be done when an object is deleted, such as freeing memory. Complete by the destructor.

In general, you do not need to provide the destructor code, the default destructor automatically self-operation.

But if the variable goes out of scope, the code cannot access it, and the variable is still somewhere in the computer's memory, only . NET The running program performs its garbage collection, cleans up, and the instance is completely removed.

static class members and instance class members , No instantiation required

static method: Console.WriteLine ();

Static constructors: Perform initialization tasks of this class, a class can have only one static constructor, no modifiers, and no parameters. cannot be called directly, only once.

Static class: Cannot instantiate an object , you can have a static constructor.

Non-static functions: That is, instance constructors

Some other features of the object :

Interface: the public instance (non- static) methods and properties are combined to encapsulate a collection of specific features.

it can be implemented in a class that supports the interfaces specified by the all of the properties and members.

    1. interfaces cannot exist alone , you cannot instantiate an interface.

    2. The interface cannot contain any code that implements its members, but can only define the member itself

    3. A class can support multiple interfaces, and multiple classes can support the same interface.

    4. and combined into an interface. This interface is ihotdrink

    5. after publishing the interface it can be used by other developers or end users, it is best not to modify it.

    6. You can create a new interface to extend the old interface.

Objects that can be deleted

Support IDisposable the object of the interface must implement its Dispose () methods, that is, they must provide the code for this method.

This method is called when an object is no longer needed, freeing up important resources.

Inherited

  1. Any class can inherit from another class, that is, the class owns all the members of the class it inherits from.

  2. C # can only be derived directly from a base class.

  3. a derived class cannot access a private member of a base class and can access its public members .

  4. only derived classes can access protected members.

  5. External code cannot access Private members and protected members.

  6. sealed class, cannot be used as a base class, no derived class.

  7. all objects have a common base class Object

650) this.width=650; "style=" Float:none; "title=" 1.png "src=" http://s3.51cto.com/wyfs02/M01/6C/E6/ Wkiom1vvxpgb4yvvaahxatkrjdi598.jpg "alt=" wkiom1vvxpgb4yvvaahxatkrjdi598.jpg "/> polymorphism

650) this.width=650; "style=" Float:none; "title=" 2.png "src=" http://s3.51cto.com/wyfs02/M02/6C/E1/ Wkiol1vvxmyagsukaaeobtutho0104.jpg "alt=" Wkiol1vvxmyagsukaaeobtutho0104.jpg "/>

650) this.width=650; "style=" Float:none; "title=" 3.png "src=" http://s3.51cto.com/wyfs02/M02/6C/E6/ Wkiom1vvxprcjhvcaar3tbep6yg031.jpg "alt=" Wkiom1vvxprcjhvcaar3tbep6yg031.jpg "/>

Relationships between objects

Inheritance Relationship: you can have derived classes get the attributes of the base class intact, and derived classes can access some work code inside the base class (through protected members).

include relationship: A class contains another class, similar to an inheritance relationship, that contains classes that control access to the members of the containing class.

Set Relationship: A class is used as a container for multiple instances of another class. Using arrays to store multiple objects

Animal [] animals = new Animal [5];

collection in the plural form of the stored object name (Animals) to name

collections typically implement additional functionality, such as Add () and the Remove () method to add and remove items from the collection.

Collection of Item property, which returns the modified object based on the index of the object.

This article comes from the "Ricky's blog" blog, please be sure to keep this source http://57388.blog.51cto.com/47388/1651516

. C #-objects, classes, interfaces, inheritance, polymorphism

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.