Chila C # Object-oriented preparation (ii)

Source: Internet
Author: User

Object-oriented (oop→object-oriented programming)

1. What is object-oriented?

A way to analyze the problem.
2. Object-oriented three major features:

Encapsulation (Covert code implementation/reuse/modification convenient), inheritance, polymorphism.
3. What is a class? What is an object? What are the differences between classes and objects? How to write a car class?

The class is the stencil that creates the object of the stencil, abstract.
A class is a data type, a user-defined data type

Class composition: Fields, properties, methods, constructors, etc.
The object is specific and is a concrete instance of the class.

Objects have attributes (features) and methods (behaviors)
Case: Creating a student class, teacher class, initializing a class inner field from a constructor function
4.this Current Object
5. Class-To-object relationships: Classes are used to describe things

Objects are the individuals that exist for such things.

The description object is the characteristic (field) and behavior (method) that describes the object.
For example:
Both teacher Yang and Liu Bo students have names, gender, age, etc.
Teacher Yang has the behavior of lectures, students have the behavior of learning

6. Differences between classes and objects:

Classes are abstract concepts, just templates, such as: "People"

object is a concrete entity that you can see and touch.

"People" categories are: name \ gender \ Age attribute, there is a way to speak.
Zhang San is the value of an object whose Name property: Zhang San The value of the attribute of the sex: The value of the male Age attribute: 20 three will speak.


An object can be called an instance of a class (Instance)
Class occupies only one piece of memory, and each object occupies a single piece of memory.

7. Definition of class:

Defined syntax:
[Access modifier] class name
{
Members
......
}
A class can contain definitions of variables, methods.

8. Instantiation of the class:

Class is instantiated with the keyword new
Syntax: class instance name = new Class ();
Access to members of the class:
Instance name. Attribute instance name. Method Name ();
Fields, Methods, properties (later speaking) can all be called members of the class member, and they all need to define the access level. The purpose of the access level is to control where members are accessible, so that the object-oriented "encapsulation" is achieved.
Access modifier: Public Private (internal protected)

9. Properties

The issue where the field is modified with public.
The definition of the property. Get;set;
property is to protect the field that corresponds to it. Ensure that fields are read and assigned in accordance with the requirements.
Attributes can be divided into: read-write, read-only, write-only
Variables that allow external access must be declared as properties
The nature of the attribute-is two methods.

10. How classes are constructed

Constructs a method to initialize the field properties of an object.
Constructors are special methods used to create objects, such as the method name and the class name, with no return value and no even void.
Constructors can have parameters, and the new object passes the function arguments.
If you do not specify a constructor, the class has a default parameterless constructor. If a constructor is specified, there is no longer a default parameterless constructor, and you need to write it yourself if you need a parameterless constructor.
Constructors can be overloaded, which means that there are multiple constructors with different parameters.
Understanding class Diagrams

Class diagrams and general class diagrams in 11.c#

12. Package:

Question: What do you think is encapsulation?
The remote control just came out very magical, click a button can change the TV station, cut the volume, turn off the TV. And the people we use the remote don't need to know how he's doing it (you just have to pay for it)
Like the remote control, object-oriented encapsulation is to encapsulate the state and behavior of a thing in a class, and the person using the class does not need to know how the class is implemented, as long as the properties and methods implemented in it are called. Just as you use the remote control, do not need to know how he controls the TV, as long as the button can change the station on the line
Classes and objects themselves are the embodiment of encapsulation.
Attributes encapsulate fields, methods, and fields as an object, encapsulate a heap of business-single code into a method, encapsulate a function into several classes, encapsulate some code with the same functionality into an assembly (DLL, EXE), and provide a unified provider for the external. (attribute name, method name, and so on.) )

13.This keywords

This
1. As an object of the current class, you can invoke members in the class. this. member (call member, OWN)
2. Call the other constructors of this class. : This () (call constructor, own)

14. Namespaces-Virtual Folder system

Namespace (namespace), used to resolve class name problems, can be seen as "folders of classes."
If the code and the class being used are in a namespace, the using is not required.
There are two methods of class invocation under different namespaces:
Write a full name namespace. class Name
The using reference namespace before invoking the

Chila C # Object-oriented preparation (ii)

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.