Talking about the importance of programming ideas

xiaoxiao2021-03-06  69

Talking about the importance of programming ideas: wfg2005 in object-oriented programming, in fact, what language you use is not the most important, the most important is the idea of ​​OOP. That is to say, we must carefully understand the object-oriented ideology in object-oriented programming.

Not a language, for the language, whether you use C , or Java or even a new language C #, they are unrestricted different. And these languages ​​(accurately said all object-oriented programming languages)

When constructing these languages, constructors are based on the same object-oriented ideas. It's just that the way used in the configuration is different. Of course, it may be different in detail outside of the details, because these languages

Word makers may be different from the perspective of the station or different views, but their "core thinking" is the same. It is consistent for the core conceptual understanding of the object-oriented object.

I don't care how I stated my point of view. Always abstract. The reader is also difficult to accept, so I will analyze and exemplify the concept of "polymorphism" for object-oriented ideas.

(For example, I will compare Java, C #, C to prove my point of view)

In order to facilitate explanation, I will introduce one of the important specials of the object to the object. It is: a simple multi-state is: a method of multiple interfaces.

Accurately, the same operation acts on different objects, can have different interpretations, producing different execution results.

We know from the above concept. Multi-state implementation is realized by way of this mechanism, of course, the method (main) referred to herein is a method (or serving service). Also explained

The data in the class is not polymorphic. From here we can conclude: in an object-oriented language (no OOPL without any OOPL) has a polymorphic language mechanism. And these implementations

Polymorphism language mechanisms are for methods. And the data is not with this nature

Let us now look at this popular object-oriented language in today's popularity.

Easy to readers understand what I will lift. Do some necessary instructions first. A total of three examples of popular OOPL are placed below.

It is. Java, C (using 1998 standard), C # (Microsoft's new language)

Base class: A Person contains two common common variables. INO, STRNAME. A constructor, a display method.

Subcrete: Inherited in the base class Person group, it also contains two commonal variables: INO, STRNAME. A constructor, a display method.

At the same time, please pay attention to: I just want to explain these three examples: "In an object-oriented language (no OOPL, no OOPL) has a polymorphic language mechanism. And these implementations

Polymorphism language mechanisms are for methods. The data is not a polymorphic this nature. Instead of starting from the rationality of the design. Of course, there are very few people who will design. I do this.

Just to make the example simple. Easy to explain the problem

// --------------------------------------------- -

Package WFGA001; Class Person

{

Public int ino;

Public String Strname;

Public Person ()

{

}

Public Person (int No, string name)

{

INO = NO;

Strname = name;

System.out.println ("Class Person");

}

Public void show ()

{// INO and STRNAME for display

System.out.println ("Class Person Ino:" "Strname:" Strname);

}

}

Class Student Extends Person

{

Public int ino;

Public String Strname;

Public Student (int No, string name)

{

Super (111, "Class Person");

System.out.println ("Class Student");

INO = NO;

Strname = name;

}

/ / The value of INO and STRNAME for display

Public void show ()

{

System.out.println ("Class Student Ino:" INO "Strname:" Strname);

}

}

Public Class Test

{

Public static void main (string [] args)

{

System.out.println ("------------------ INTANCE OF CLASSON: OBJ ----------------- ------- ");

Person Obj = New Person (2, "Weng");

System.out.println ("Obj.ino:" Obj.ino "obj.strname:" Obj.StrName);

Obj.show ();

System.out.println ("----------------------- Intance of class student: Obj2 ----------- ---------- ");

Person obj2 = new student (5, "weng fu guo");

System.out.println ("Obj2.ino:" obj2.ino "obj2.strname:" Obj2.strname);

Obj2.show ();

}

}

// Result in Java

/ *

------------------- Intance of class persons: Obj --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Class Person

Obj.ino: 2 obj.strname: Weng

Class Person Ino: 2 Strname: Weng

------------------------------------------------------------------------------------------------------------------------------------------------ ---

Class Person

Class Student

Obj2.ino: 111 Obj2.strname: Class Person

Class Student Ino: 5 STRNAME: Weng Fu Guo

Press any key to continche

* /

// ---------------------------------------- ------ # include

#include

Using namespace std;

Namespace WFGA002

{

Class Person

{

PUBLIC:

INT INO

String strname;

PUBLIC:

Person (int No, string name)

{

COUT << "class person" << endl;

INO = NO;

Strname = name;

}

PUBLIC:

Virtual void show ()

{

Cout << "Class Person ino:" ino << "strname: << Strname << endl;

} // end functin show ()

}; // end class Person

Class Student: Public Person

{

PUBLIC:

INT INO

String strname;

PUBLIC:

Student (int No, string name): Person (111, "Class Person")

{

COUT << "class student" << endl;

INO = NO;

Strname = name;

}

PUBLIC:

Void show ()

{

Cout << "Class Student Ino:" << INO << "strname: << Strname << endl;

}

}

} // end namespace WFGA002

Using Namespace WFGA002;

// Number of main

void main ()

{

Person * Obj, * Obj2;

COUT << "------------------- Instance of class persons: Obj --------------------- - "<< Endl;

Obj = New Person (2, "Weng");

Cout << "Obj-> ino:" << obj-> ino << "obj-> strname:" << obj-> strname << ENDL;

Obj-> show ();

Cout << "------------------ ---------------------- << endl;

Obj2 = new student (5, "weng fu guo"); cout << "obj2-> ino:" << obj2-> ino << "obj2-> strname:" << obj2-> strname << endl;

Obj2-> show ();

}

/ *

------------------- Instance of class persons: Obj ---------------------------------------------------------------------------------------------------------------------------------------

Class Person

Obj-> ino: 2 Obj-> strname: Weng

Class Person Ino: 2 Strname: Weng

----------------- Instance of class student: Obj2 --------------------------------------------------------------------------------------------------------------------------------------

Class Person

Class Student

Obj2-> ino: 111 Obj2-> strname: Class Person

Class Student Ino: 5 STRNAME: Weng Fu Guo

* /

// ------------------------------------------- ----

Using system;

Namespace WFGA003

{

// base class Person

Class Person

{public int ino;

Public String Strname;

Public Person (int No, string name)

{

System.Console.writeline ("Class Person");

INO = NO;

Strname = name;

}

Public Virtual Void show ()

{

System.console.writeline ("Class Person INO: {0} strname: {1}", ino, strname;

}

}

// Sub-class Student

Class Student: Person

{

New public int in;

New public string strname;

Public Student (int No, string name): Base (111, "Class Person")

{

System.console.writeline ("Class Student");

INO = NO;

Strname = name;

}

Public override void show ()

{

/ / Display the value of INO and STRNAME

System.console.writeline ("Class Student Ino: {0} Strname: {1}", Ino, Strname);

}

}

Class class1

{

// Number of main

Static void main (string [] args)

{

System.console.writeline ("------------------ instance of class person ------------------- ----- ");

Person Obj = New Person (2, "Weng");

System.console.writeline ("obj.ino: {0} obj.strname: {1}", obj.ino, obj.strname;

Obj.show ();

System.console.writeline ("---------------------- --------------- ----- ");

Person obj2 = new student (5, "weng fu guo");

System.console.writeline ("Obj2.ino: {0} Obj2.strname: {1}", obj2.ino, obj2.strname;

Obj2.show ();

}

}

}

/ *

Results in C #

---------------------------------------------------------------------------------------------------------------------------------------

Class Person

Obj.ino: 2 obj.strname: Weng

Class Person Ino: 2 Strname: Weng

------------------------------------------------------------------------------------------------------------------------------------------------

Class Person

Class Student

Obj2.ino: 111 Obj2.strname: Class Person

Class Student Ino: 5 STRNAME: Weng Fu Guo

* /

From the above three languages. I think it is enough to explain the conclusion.

I still want to emphasize this by the above example. No oOPL is all OOP ideas with the same core, only achieved.

So, the most important thing for us is to completely understand the OOP thinking. If you understand the object of object, it is very thorough. So no learning

Which OOPL is no longer difficult. This happens to use the OOPL in practice. Just learn the corresponding class library and look at an OOPL grammar book.

Because there is an object-oriented thought, it is easy for learning syntax.

It can also be used in practice.

转载请注明原文地址:https://www.9cbs.com/read-90336.html

New Post(0)