The Three Kingdoms period , Cao Cao led a million troops to attack the eastern Wu Dynasty , The army is stationed in Chibi of the Yangtze River , The ships are in one piece , Soochow is about to be destroyed , Unify the world , Cao Cao is very happy , So Yanzhong Wenwu , Between the drinks , Cao Cao's poetry flourished , I don't know :“ Drinking and singing , Life is wonderful ”, All men and women call :“ Prime Minister's good poetry !” So a minister quickly ordered the printer to print , In order to spread it all over the world . Let's show the samples to Cao Cao , Cao Cao doesn't feel right , Say :“ Drinking and singing , This is too common , Should be changed to ‘ sing while drinking ’ good !”, So the minister ordered the craftsmen to come again , Craftsmen see the work of night engraving , It's all in vain , Depressed in my heart , I have to do it . The sample is coming out again. Please have a look at it , Cao Cao is very careful , I think it's still not good , say :“ Life is so cool. It's so direct , We should change the language to be artistic , Therefore, it should be changed to ‘ sing while drinking , Life geometry ?’” When the minister tells the craftsman , The craftsman vomited blood and died ! Unfortunately, movable type printing was not invented in the Three Kingdoms period , So similar things happen , If there's movable type printing , Just change the character , It's wonderful .

So , Movable type printing, one of the four great inventions, is an object-oriented victory , Everything in the world is connected , How is movable type printing perfectly combined with our object-oriented technology ? First of all , To change , Just change the words you want to change , This is maintainable ; second , These words are not useless this time , It can be reused in later printing , This is reusable ; Third , If you want to add words to this poem , Just carve another word to add it , This is scalable ; Fourth , The typesetting of Chinese characters may be vertical or horizontal , At this time, just move the movable type to meet the arrangement requirements , This is flexibility . But before movable type printing , None of the above four features can satisfy , To be modified , It has to be re engraved , I want to add words , It has to be re engraved , To rearrange , It has to be re engraved , After printing this book , This edition has no value to use .

From the above story , Think of knocking on the student management system and computer room charging system , To achieve a function , Our intuition is to use the logic that the computer can understand to describe and express the problem to be solved and the specific solving process , This is actually thinking in a computer way , For example, in the computer room charging system , The little function of computer operation , The logical thinking is as follows :

Make a corresponding judgment according to our logical thinking , Get the little function we want to achieve on the computer , There is nothing wrong with the process itself , But this kind of thinking makes our program only to meet the current needs , Lack of soul , This kind of software is not standardized , It's not easy to maintain , Not easy to expand , And not easy to reuse . So what is object-oriented ? What a magical face , Next , We turn a new page :

object-oriented Knowledge , There are related introductions in the previous blog , I won't repeat it one by one , In general, the main advantages of object-oriented and the differences between object-oriented and process oriented , as follows :

There are two important concepts in object-oriented programming ,Class and Object, as well as OMT And the three basic characteristics of object orientation , The details are as follows :

I have some basic knowledge of object oriented , And the control of classes and objects , Let's learn more about C# Class in , Class is a custom data type , Just like integers and characters , You can use classes to declare variables , Variables declared with a class are called reference variables , therefore , Classes are referential data types ,C# Provides the ability to create classes and objects , use C# When programming , The main task is to define the kinds of programs that make up the program , A class definition can be used as a template or blueprint , Encapsulates the data and behavior of her objects , Once the class is defined , You can use her as a template to create objects and instances of a class , that , Next , We use C# An example in the video - Change the password to see , Class creation and instance , First , What we need to do is declare a password that can determine whether the password is correct , And can change the password of the class , And define related methods in the class :

 class Authentic // Declare a key to determine whether the password is correct , And can change the password of the class
{
private string PassWord = "dengyigegushi"; // Define the password in the class
public bool IsPasswordCorrect(string userPassword) // Declare a method in the class to determine whether the password is correct
{
return (PassWord == userPassword) ? true : false;
}
public bool ChangePassWord(string oldPassWord, string newPassWord)// Declare the method to change the password in the class
{
if (oldPassWord == PassWord)
{
PassWord = newPassWord;
return true;
}
else
return false;
}

Instantiate the class

 class Program
{
static void Main(string[] args)
{
Authentic simon = new Authentic(); //simon yes authentic The name obtained by instantiation
bool done;
done = simon.ChangePassWord("dengyigegushi", "dangxingfulaiqiaomen");
if (done == true)
Console.WriteLine(" The password has been changed ");
else
Console.WriteLine(" Password change failed !");
}
}

Let's take another small example , The creation of class is described in detail :

[< Access specifier >] [< Modifier >] class <classname>

{

//body of class

}

among class yes C# The keywords used to create the class ;<classname> Is the name of the class ;<body of class> Is a member of the class , It mainly includes properties and methods !C# The journey , To be continued ......

C# More articles on object oriented

  1. angular2 Series of tutorials ( 6、 ... and ) Two kinds of pipe: Functional programming and object-oriented programming

    today , What we are going to talk about is angualr2 Of pipe This knowledge point . Example

  2. Learn together Java( Two ) object-oriented

    One . Method function Functions are also called methods , Is defined in the class with a specific function of a piece of independent code . Used to define functions , Improve code reusability . Features of functions 1> Defining function can encapsulate function code , It is easy to reuse this function :2> function ...

  3. js Object oriented learning - Object concept and creating objects

    Original address :js Object oriented learning notes One . Object concept What is the object ? The object is “ A collection of unordered properties , Its properties can include basic values , Object or function ”. That is, an unordered set of name value pairs . Properties of objects ( Not directly accessible ), That is, there are two kinds of attributes , Count ...

  4. The front-end development : Object oriented and javascript Object oriented implementation in ( Two ) Constructors and prototypes

    The front-end development : Object oriented and javascript Object oriented implementation in ( Two ) Constructors and prototypes Preface ( Digression ): Some people say procrastination is a terminal disease , Oh, it can't be cured . Let's not say that this is something that everyone will have more or less , No matter how important it is to life ...

  5. .NET Basics Step by step, Scene after scene [ Object oriented objects and classes ]

    Objects and classes This article formally enters the object-oriented knowledge point brief introduction : What is the object , Buddha says : A flower a world , To see a life in a tree , One grass, one heaven , One leaf, one Tathagata , One sand, one bliss , One side, one pure land , A smile and a dust , Read and be quiet . so " Everything is object ". ...

  6. Simple analysis JavaScript Object orientation in

    Beginners JavaScript Some people think that JavaScript Not an object-oriented language , because JS There is no concept of a class , But that doesn't mean JavaScript There is no object , and JavaScript It also provides other ways ...

  7. Java What programmers should know 10 Object oriented design principles

    Object oriented design principles : yes OOPS(Object-Oriented Programming System, Object oriented programming system ) The core of programming , But most Java Programmers are chasing things like Singleton.Decorat ...

  8. JavaScript Learning notes ( 3、 ... and )——this、 Prototype 、javascript object-oriented

    One .this stay JavaScript in this Express : Who calls it ,this Who is the . JavaScript It's made up of objects , Everything is the object , All things are objects .this It's a dynamic object , Depending on the object being called , ...

  9. Take you a minute to understand closures --js object-oriented programming

    Last one < To understand simply and roughly js Prototype chain --js object-oriented programming > I didn't expect to save so much praise , It was an accident . Sharing is a good thing , Especially share your learning experience . So online about prototype chains . Closure . There are so many articles on scope , A lot of articles are written ...

  10. .NET Basic information (2) Object oriented implementation and exception handling foundation

    Index : (1) Types of grammar . Memory management and garbage collection Foundation (2) Object oriented implementation and exception handling foundation (3) character string . Set and flow (4) entrust . event . Reflection and properties (5) Foundation of multithreading development (6)ADO.NET Open with database ...

Random recommendation

  1. DateHelper.cs Date time operation auxiliary class C#

    //==================================================================== //** Copyright classbao.com ...

  2. QT The solution of notes QT5.2.0 and VS2012 Chinese garbled And in Qt Creator Wrong report in Chinese

    Reprint :http://bbs.csdn.net/topics/390750169 VS2012 Chinese garbled 1. Method 1 : Include header file #include <QTextCodec> ....... ...

  3. js Advanced programming ( 5、 ... and ) Reference type

    Object type establish Object There are two ways of example . The first is to use new Operator followed by Object Constructors . var person = new Object(); person.name = &quo ...

  4. VC++ Double buffer to keep the background from erasing

    A few days ago , I finally overcame C++ Flicker problem when redrawing the form , The trick is double buffering . But how to keep the drawing ? That is to imitate Windows Its own drawing program is general , Make a straight line dynamically . The easiest way to think of it is in MouseMo ...

  5. iOS Some common parallel processing in development ( turn )

    This article focuses on some common best practices for multitasking . Include Core Data Multithread access to ,UI Parallel rendering of , Asynchronous network requests and some solutions to deal with large files when the running state memory is tight . In fact, there are many pitfalls in writing asynchronous processing programs ! therefore , this paper ...

  6. Shortest path algorithm template set (Dijkstar,Dijkstar( Priority queue optimization ), Multi source shortest path Floyd)

    Before we start again, let's popularize the simple knowledge of graph theory The preservation of pictures : 1. Adjacency matrix . G[maxn][maxn]; 2. Adjacency list Adjacency table we have two ways (1)vector< Node > G[maxn]; This ...

  7. lambda calculus

    First understand the relevant knowledge ( Here are just a few simple concepts , Suggest wiki): BNF normal form , Context-free grammar , The function is coriolized . lambda Books, notes, calculus : http://www.blogjava.net/wxb_nud ...

  8. Together talk GDB Well ( The sixth time :GDB Change the program execution environment )

    Ladies and gentlemen , Hello everyone , Last time we said GDB The ability to view information , And how to use it GDB Check the execution time of the program Information . This time , Let's continue GDB Debugging function of : Change the program execution environment . Yes, of course , We'll also show you how to use GDB ...

  9. debian install android studio Environmental Science

    jdk Environment variable configuration : ~/.hashrc export JAVA_HOME=/usr/share/jdk1.8.0_92 export PATH=$JAVA_HOME/bin:$PATH export ...

  10. jquery-2.0.3 Source code analysis The overall architecture

    The key var jQuery = function( selector, context ) { return new jQuery.fn.init(); } jQuery.fn = jQuery.pr ...