Object-Oriented---4

Source: Internet
Author: User
Tags iusb

Object-oriented three major features: encapsulation, inheritance, polymorphism
First, Package:
Field (member Variable) property method (member function) constructor
Instance
Static

second, inheritance: Single inheritance.
(a) What is inheritance?
1. The parent class member is derived to the child class.
2. Subclasses can extend the parent class.
3. Subclasses can override the parent class. Subclass object is a parent class

(ii) Inherited syntax:
Class Subclass Name: Parent class name
{
}

(iii) Rules of Succession:
1. Inheritance of fields
2. Inheritance of attributes
3. Inheritance of methods
4. Inheritance of constructs

three, polymorphic:
(a) Compile polymorphic (static polymorphism): The overloading of the method is implemented.
(b) Operation polymorphism (dynamic polymorphism): Inheritance and rewriting.
Running polymorphism is implemented on the basis of inheritance.
The parent class references an instance of the child class.

Example: Eating. Feed the animals.

Iv. abstract class:Abstract
Abstract method: Only the declaration of the method, there is no implementation of the method. Abstract
public string SetName ();
Abstract properties: Only declarations of attributes, no property implementations.
public string Name
{
Get
Set
}
The relationship of abstract methods (attributes) to abstract classes:

1. Classes with abstract methods (attributes) are definitely abstract classes.
2. Abstract classes do not necessarily have abstract methods (attributes).

Interface: Only the declaration of the method, the declaration of the property. There is no implementation, and there are no member variables.
Grammar:
Define interfaces:
Interface Interface Name
{
return type method name ();
Property Type property Name
{
Get
Set
}
}
Implementing the interface:
Class Name: Interface name, interface name ...
{
}
Interface Interface Name: interface Name, interface name ...
{
}
The implementation of the interface can implement multiple interfaces.
Each class can have only one parent class, but it can implement multiple interfaces at the same time.
Cases:
Interface openable
{
void Open ();
}

Class Window:openable
{
}

Interface: Make rules. The associated class is a subclass of the interface as long as it implements the interface. Other devices or processes are set at the time of invocation, as long as the call based on the interface, the corresponding device or program will be transferred to.

Interface ****************

Namespace ConsoleApplication1
{
Interface Iusb
{
void Start ();
void Stop ();
}
}

Inheriting child functions **************

Namespace ConsoleApplication1
{
Class Udisk:iusb
{
public void Start ()
{
Console.WriteLine ("USB stick boot, can read and write data. ");
}

public void Stop ()
{
Console.WriteLine ("U Disk safe exit. ");
}
}
}

Namespace ConsoleApplication1
{
Class Kaoqinji:iusb
{
public void Start ()
{
Console.WriteLine ("Time attendance machine starts ....") ");
}
public void Stop ()
{
Console.WriteLine ("Attendance Machine safety exit");
}
}
}

Main function *************

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using HQ. test.cyl;

Namespace ConsoleApplication1
{
Class Program
{
static void Main2222 (string[] args)
{
Computer C = new computer ();
Mouse m = new Mouse ();
Udisk u = new Udisk ();
C.startusb (m);
C.STARTUSB (U);
Kaoqinji k = new Kaoqinji ();
C.startusb (k);

C.stopusb (k);


}
}
}

Call Function *************
Namespace ConsoleApplication1
{
Class computer
{
public void Startusb (IUSB USB)
{
Usb. Start ();
}
public void Stopusb (IUSB USB)
{
Usb. Stop ();
}
}
}

Namespace ConsoleApplication1
{
Class Mouse:iusb
{
public void Start ()
{
Console.WriteLine ("Mouse started, you can use the mouse to operate the computer.") ");
}

public void Stop ()
{
Console.WriteLine ("The mouse device stopped. ");
}
}
}

Namespace HQ. Test.cyl
{
    public class Mouse
    {
         public void Show ()
        {
             Console.WriteLine ("This is not a mouse, it's a mouse!" ");
       }
   }
}


namespaces, projects, assemblies.
(a) Namespace: namespace.
Role: Logical classification management of classes. Under the same namespace, the class name is not allowed to be duplicated.
Use:
1. At the beginning of the code, use the using XXXXX; the namespace is directed in. You can omit the namespace when you use the namespace later.
2. Each time a class is used, the namespace is written before this class, that is, the fully qualified name of the class is used. If a class with the same name appears in all the different namespaces, the fully qualified name is used when the class is used.

The namespace is different from the Java package. Java packages have both logical and physical locations. The. Net namespace is just a logical concept.

How do I set the default namespace?
Right-click on the project icon in Solution Manager, select Properties, and set the default namespace.

(ii) Project
The project is mainly used to manage all documents of the project.

(iii) ASSEMBLY
Is the intermediate code that the program compiles when it runs.. exe or. dll. They are not binary as compiled as C or C + +. It is the intermediate code (IL)
The C # language is two-step editing: The first step: compiling from the source code to IL. The second step: the runtime is compiled from IL into binary. In the running memory we call the assembly

Object-Oriented---4

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.