Object-oriented C # - Encapsulated

  A, abstraction and encapsulation are basic features of object-oriented programming, the abstract to ignore details of the process at different levels of detail, the package is achieved varying degrees of access to detail; i.e. abstraction allows visualization of information, for packaging to achieve the required level of abstraction;

  1. In accordance with the principles of encapsulation, wherein each of the namespace can specify the type of the external code accessibility, type and structure of each member can specify external code accessibility, accessibility can control whether the current program set of codes or other access assemblies thereof, to prevent the possibility of coding errors and malicious attacks occurring;

  Second, in C # by four kinds of access modifier (Access Modifier) ​​and a combination of two elements set to access modifiers accessibility:

  1. The default namespace is the public, without any access restrictions, can not use any access modifiers;

  Five basic types (Class class, struct structure, the interface interface, enum, and enumeration delegate delegate) 2. defined in the namespace, only public or internal default is the internal;

  ※ derived class does not allow accessibility accessible than the base class;

  3. internally declared members of different types, only allows you to specify certain access or allowed to specify any accessibility, if you do not specify an access modifier in the member declaration, the default accessibility will be used:

   ※ special commission type does not contain any custom member; static constructor, destructor not include any access modifiers;

  ※ Typically, members of the accessibility of not higher than the declared type of the member is accessible, however, if the internal members of the class implements the common interface method or overrides the virtual method in the common base class definition, abstract the method can be accessed from within the assembly to the other member;

  ※ fields, properties and types of events can not be lower than the access of members of accessibility, methods, indexers, and type of delegate's return value and parameters of accessibility must be at least accessible to the members; these operation will cause a compiler error:

 1 class MyClass { }
 2 public class MyPublicClass
 3 {
 4     public MyClass MyField; //CS0052
 5     public void MyFunc(MyClass obj) //CS0051
 6     {
 7         //do…
 8     }
 9     public MyClass MyFunc() //CS0050
10     {
11         return new MyClass();
12     }
13 }

 


If you feel that you have read this article to help, please click the "recommend" button, your recognition is the greatest power of my writing!

Author: Minotauros
Source: https://www.cnblogs.com/minotauros/

This article belongs to the author and blog Park total, welcome to reprint, but without the author's consent declared by this section must be retained, and given the original connection in the apparent position of the article page, otherwise the right to pursue legal responsibilities.

Guess you like

Origin www.cnblogs.com/minotauros/p/11610368.html