Delphi object-oriented programming ideas
Liu Yi
Forehead
The first time I knew that Delphi was not because Borland's Delphi software, but read this word in Plato's classic book "Plato to dialogue".
A friend of mine.. Went to
Delphi
And boldly asked the oracle to Tell Him WiTher.. There Was Anyone Wiser Than I Was, And The Pythian Prophetes Answered That There was no one wiser..
Delphi and the wisdom of Socrates
Delphi is the predicted god Oracle residence. "Plato dialogue" records a friend in Socrates to Delphi to ask the goddess Pythian who is the most wisdom. Pythian said no one is more wisdom than Socrates. Socrates are deeply disgraced because he finds that there are many politicians, poets, philosophers and artists. Is these experts and "authority" not more wisdom? I am more than they.
Socrates visited these "experts" and "authority" one by one, but they often think that they are self-righteous, and they don't understand what they don't understand. Through visit, Socrates also found that he knows much in many ways. But Socrates did not understand it, he frankly his own ignorance. This is the true "wisdom" that prophesies with Goddess Pythian.
In fact, this wisdom is not the earliest of the ancient Greeks. Before the Socrates, my country's Laozi has been summed up. "Tao Te Ching" has "Knowledge people's wisdom, self-knowledge", this is also.
Now, we use Delphi is already an excellent programming language and software development tool. However, in the face of the profound and continuous development of Delphi, we also know very little in many ways. However, when learning and using Delphi, is we also have the idea of Socrate's self-knowledge and unknown wisdom?
There are many friends who choose Delphi, the initial idea may be because the Delphi is powerful, easy to learn. They didn't even have experienced Delphi even three months, and I dared to develop software independently. In fact, what they can do is just the drag of the control. When they are intoxicated for their own procedures, they are actually inhapse for Delphi's exquisite and other people's controls. This Delphi programmer is often called "drag" member. And they live in Delphi masters.
There are also many friends who give up Delphi, the initial idea may be because Delphi is just a similar VB's RAD tool. In their view, Delphi is the control programming, can't really implement OOP like C or Java. They suspect that Delphi does not have the characteristics of object-oriented programming languages, and can not achieve object-oriented technologies such as polymorphism, mode. In their eyes, only talents using C or Java are real masters.
So, what is a real master, how can I become a master?
On "Mero" and "气"
First let's take a look at what is a martial arts master, maybe we can get inspiration from it.
Everyone who loves martial arts or martial arts novels knows that cultivation martial arts is divided into two ways to practice and internal repair. Foreign training, weapons, fists, and weapons are the key; internal repair is true, practicing gas, practice God is also true. The maximum difference between these two cultural methods is on the functional relationship of time and power, as shown in Figure 1. Popularly, the first 3 years, the practice of external work can be easily defeated; in the first 10th, both sides can only play a flat hand; after 15 years, no matter how you practice the external work is not the opponent. 20 years later, the internal master is invincible. The truth is in the dialectical relationship between "instruments" and "gas".
"The device" is a tangible thing, the knife gun swords, all of which are tangible. Foreign training martial arts, inseparable from these tangibles, practicing the training. So make the martial arts master of the gun in the sword often depend on the quality of the weapon. The intangible quality of "qi" is all wisdom, mana, and thought is invisible. The internal repair is inseparable from these intangible quality, and the practice is the practice. So the real martial arts master often do not need to rely on a specific weapon. For them, any tangible things can be transported, intended to be weapons. One fold fan, a dust in his hand is not a strong sword, it is also gas.
Figure 1 Time and Strong Function of Two Methods
In software development, programming tools are "devices", programming ideas are "gas".
In the programming, ease of use, such as VB, PB; it is difficult to use, such as compilation, C ; ancient instrument such as Fortran, COBOL; fashion instruments such as Java, C #.
In programming ideas, there are object-oriented and process-oriented points, they are both a worldview and methodology. The former reflects the way of thinking of objective objects, which reflects the way the machine's thinking of the instruction. In the continuous practice of software development, the superiority of the former has been constantly reflected and confirmed.
Master the object-oriented programming thought as the true meaning of the training. Its importance is often better than the choice of programming language!
Even if you choose an object-oriented tool, you can't be a real master. Because he value the "device", it is ignored "gas" practice.
In fact, "A system or language is not object-oriented, what is important? How can it be an object-oriented and related benefits? ("Object-Oriented Method: Principle and Practice" Machinery Industry Press March 2003)
Although the construct is easy, it is difficult to become a master. Although the gas is good, but the effect is slow, loneliness is difficult to resist, and non-general ordinary people can see sex and direct avenue. Therefore, many martial arts masters are the first suspector, the post-abortion; the inside and outside is improved, and it has become a fruit.
For new hands in the martial arts, they need the power of the weapons to make up the insufficient internal force, the quality of the instrument is often important. But with the increase of martial arts, the inner strength, the dependence of the counter should be reduced. "God Carving Heroes" Yang Hao Jian, starting to start school, so make the sword, it is a sword, and the branches are also a sword after the internal practice. So for true masters, the quality of swords is often not important.
Similarly, the growth of software masters has this process. The beginner programming needs to choose a good language, so you can get the effect of halving, while stimulating interest, enhance confidence. Once you are familiar with a language, you should have an opportunity to master the object-oriented programming ideas. At this time, you are not a language itself, function, class library, but binding, polymorphism, mode and other thinking methods, then touching bypass, learning other object-oriented languages is not difficult. Dressing hard, courageous, and finally successful real software masters, is not subject to programming languages. They may be more familiar with a development tool, but it is only carrying their unavoidable utensils. They are kind to learn, and they are good at summarizing. Their thoughts, methods, patterns, and even philosophy have transcend the programming language and guide the praise of the programming language.
Delphi provides shortcuts for internal and external repair for the growth of software masters. Learning Delphi, you can use its RAD long, the control of the control, start school, quickly defeat the opponent; learn Delphi, you can also use its OOP energy, VCL strong, bacon, and achieve unbeaten work.
The Huashan Sword of the Weihai Sihai was divided into "Jianzong" and "gas", the former practitioner, trick; the latter is holding the gas, renovate the foundation.
Learning Delphi is like repairing Huashan sword law, walking the road of RAD is "Jian Zong", from OOP's way is "gas". The former is like to use the control, see the Chinese knee, the latter is good, keen method mode. The former pursues the speed, the latter is high. I don't really understand Delphi, whether Delphi for Rad or IOOP is not really understanding Delphi. Delphi is a nice RAD development software, but it is difficult to become a real master without learning OOP. Similarly, Delphi is an authentic OOP programming tool that combines Delphi powerful RAD and efficient compilers, which can have more advantages and higher efficiency than other OOP languages. If you can break the door, "the device" "gas" is practicing, inside and outside, I believe that the Delphi programmer is not difficult to grow from a RAD trick to the OOP master, and finally smile the rivers and lakes, and the sea.
Object-oriented programming ideas and avenue invisible
I quickly discussed the dialectical relationship between "instrument" and "gas". In programming, one of the keys to improve internal power is to master object-oriented programming ideas. In fact, I think more about object-oriented thinking is the same as the invisibleness of the avenue.
Why do you say this? "The ancient China, it is a bitter," "" Ghost Valley "reaction second), the mystery of the gas is first in its" zoom ". Dacheng, the bigification of the heavens and the earth, and the intensiveness of all creation and changes. Object-oriented programming ideas have this type of traits.
Laozi, "The beginning of the unknown heaven and earth, the mother of all things", is not named, nothing to define. The so-called object-oriented thinking, the most mystery is how to identify and define objects from "unknown", how to construct and use objects from "有名".
For software developers, the process of understanding objective entities, analyzing and designing user needs, is the process of discovering and defining the object, is from unnamed to a famous process. However, the objects here are different from the variables or functions in the process, and the object is created by the class, the class is an abstraction of the concept, which is the "ample name" that can be defined is the mother of the object.
So, Tai Chi students, two instruments, gossip, through the inheritance and derived, all things, system.
Even "the" device "facing the object-oriented programming tool, also embodies and carries the" gas "of object-oriented programming ideas.
The first sentence "Zhou Yi ginseng" opened in the "Wan Yi Zhi", the first sentence "Qiankun, the portal, the gang, the parents, the cookie, the hub positive axis, 牝Music gossip, I thought it was. "
From the perspective of software development, although object-oriented programming tools provide the possibility of building an infinite type software system, this infinity is built in the limited framework of its own class library. Whether it is Delphi's VCL, or a Java class library, or a .NET framework, none is not built in such an architecture similar to the Zhou Yi gossip. "It is easy to have Tai Chi, Tai Chi, two elements, four elections, four elephants", such a structure is perfect, there is endless creativity.
Tooji is the TOBJECT in delphi, which is the atom of building a system, which is all kinds of ancestors, which has the basic characteristics of all class. In Delphi's programming world, root TOBJECT Suspension Object class TPERSISTENT, persistent object class TPERSISTENT Biographic Object class Tcomponent, which provides a rich control and powerful feature for development applications.
However, the structural framework of the class library is not only a component that can be used as a "instrument", but more importantly, this structure has passed the relationship and related effects of the class, which realizes the construction and changes of "gas", reflecting the objective object. The essence of programming ideas. Provide a great demonstration for our own system. The mystery of the gas is its "born in invisible". There is no free, open, adaptability. In the case of object-oriented programming, it is full of "qi" in this avenue invisible wisdom.
For example, polymorphisms in programmed objects allow programmers to write more universal, more open programs. The programmer can write a pure virtual abstract method for the Vehicle object STOP (), which is unrelated to what car driving. Programmers allow derived classes to worry about how to complete the Stop () method, and continue to write their own general processes at a higher abstract level. Even if the STOP () method of the Car object is completely different from the Stop () method of the Bicycle object, the programmer can also use VEHICLE.STOP () and polymorphism to automatically know which suitable method will be called. . This makes the program have an openness and adaptability of "gas".
In the practice, "Shangde is not for, not for inspection. Due is it," ("Zhou Yi ginseng")
In object-oriented programming ideas, "Shangde" is a purely abstract method of evening bindings, which is to interface with non-changed objects, which is the height of things, and it is met. "Shangde is not" means that in the abstract level, through the unfamiliar performance of the program "virtual", because it is not possible to determine the actual object (possibly a Car object may be a BiCycle object, more likely to invent later New transport objects), "do not seek" requires us to jump out of the specific needs, do not consider the specific implementation code. So a pure virtual abstract method or an object interface is not required to be implemented.
In object-oriented programming idea, "down moral" is a coverage of pure virtual abstract methods and is the implementation of the object interface. "Demo is", providing a real code implementation. "It is not used" to meet the changing needs.
The polymorphism allows the programmer to derive objects and implement procedures. Suppose programmers build applications for Car and Bicycle, do not know that there is still TRUCK, but this is not tight. The programmer can write a method of covering the STOP () for the Car and BiCle classes of the VEHICLE class. In this way, in the program, simply transform the created car and bicycle objects into VEHICLE, use the VEHICLE's STOP () method to dynamically bind the Stop () method that meets your requirements. Even after later added TRUCK objects, it is still called the VEHICLE's STOP () method, and there is no need to further change the program.
"There is natural, there is a problem. There is near and invisible, there is far and can be seen. Nearly not visible, it is also unable to say; far and know, it is also known to test." ("Ghost Valley" Arrive outside the fourth)
Although objective things are complex, user needs are changing, but there is also a certain internal law.
Nearly invisible, only see the specific functionality in front of you, the general development rules of the things, only the isolated data and mechanical processes in the heart, once "things are incomplete", it is difficult to deal with it. Such programming is static, mechanical, difficult to maintain and expand.
Farm and known, be good at discovering the law, pay attention to the code reuse, the eyes are all organic objects and harmonious relationships, even if the demand changes, it can be paid, and there is more time. Such programming is dynamic, flexible, maintainable and scalable.
Paul Kimmel said in the "Delphi6 Application Development Guide" "to use the object-oriented tool in a non-object-oriented approach. Writing the structured program using Delphi can quickly reach the beta version ... Your program may never get from Beta Edition. Quickly get the wrong answer, still wrong. "It is also use Delphi. If there is no object-oriented programming idea, it is better than" I don't want to say ", it is still" nearing ", it is difficult to develop outstanding system. Only the hard work, summarize, master the profoundness of object-oriented programming ideas, can wear "gas", "anti-to test", ultimately reach the realm of "far away".
About this book
It has been more than 30 years of history from the language of the first real face-to-object language. However, the bookstore is full of object-oriented booking books, which seems to be in the object-oriented language, and the actually object-oriented language has 4 basic branches, nearly 20 kinds. Since Delphi is very book-oriented, many programmers have to give up Delphi in order to learn OOP. This is a big sadness of Delphi. When I read the "Thinking in Java" of Bruce Eckel, I lamented why there is no such Delphi masterpiece?
In fact, Delphi launched a name, she was developed by Borland on the basis of Object Pascal. Now, Borland starts using Delphi Language from Delphi7 to replace Object Pascal called [1]. Delphi is actually not inferior to C and Java in OOP. This reader can see the Appendix "Object-Oriental Programming Language Comparison: Java, C and Delphi".
To this end, I have been intending to write a book of Delphi-oriented programming, summarizing my own learning experience and practical experience in Delphi-oriented programming. However, this is a difficult job, and the book is spent for a long time from conception until May this year. Just a 20th anniversary of Borland this year, as a user of Borland products Delphi, the publication of the work is also a commemoration of this.
This is a pure discussion of Delphi object-oriented book, object-oriented is not the fashion embellishment of this book, but the core and all of this book.
This book is started from the historical and current situation of object-oriented programming and the basic concepts of object-oriented programming methods and UMLs, as well as object-oriented modeling methods and UML applications. This chapter is to help readers build object-oriented basic concepts to understand object-oriented thinking methods.
Chapter 2 "Delphi Object Model" introduces the basics of Delphi object-oriented programming and its object model structural system.
Chapter 3, "Understanding Objects" from the object's nature, life and death, relationships discussed the internal mechanism, life cycle, interaction of the object, and laid the foundation for readers to understand and master objects.
Chapter 4, "Object" explains how efficiently uses objects in Delphi object-oriented programming. Here you focus on the use of interface objects, component objects, objects, and object parameters, and think deeply in the use of VCL components and the common problems in the development.
Chapter 5, "In-depth polymorphism" introduces the concept of polymorphism and its application in programming. Among them, important concepts and thinking methods such as overloading and coverage, imaginary method, dynamic methods, abstract classes, and abstract methods, type conversion, etc.
Chapter 6, "Analyzing Interface", fully introduces programming knowledge and application skills of the object interface. The interface is expounded in achieving dynamic binding and multiple inheritance, demonstrating the actual usage of the interface in object-oriented programming.
Chapter 7 "Research Package" clarifies the importance of important significance and application principles in object-oriented programming, and further discusses the implementation methods and application skills of the package from logically packaged and physically packaged.
Chapter 8 "Separation of Interface and Business" will apply object-oriented programming to a new height. This chapter explains how to use object-oriented design to evolve a desktop program to distributed multi-layer systems. And join the latest Web technology of Delphi, introduce how to use the Web Service package business object, with the Web Form package interface object, to encapsulate the old object with the new technology, thereby achieving cross-platform applications. Finally, the "deep shallow VCL" in Chapter 9 and 10 of this book has studied the internal mechanism of VCL and analyzes the object usage of VCL important class, and provides a reference for readers who are eager to improve programming levels.
From the composition of this book, it can be divided into 5 parts.
Part 1, the first two chapters of the book are entry of Delphi object-oriented programming. Readers who have mastered object-oriented basic concepts and Delphi programming experience can skip these two chapters.
Part 2, Chapter 3, 4 is the key to Delphi object-oriented programming. If you don't master the essence of the object, you cannot use a good object.
Part 3, Chapter 5, 6 is in-depth of Delphi object-oriented programming. Object-oriented advanced skills are not established in dynamic binding mechanisms such as virtual methods, abstract methods, object interfaces and upward transformation, down transformation, interface transformation, and other translation mechanisms.
Part 4, Chapter 7, 8 is the application of Delphi object-oriented programming. In order to achieve the maintenanceability, scalability, and reusability of the program, the package has become one of the important ideas of object-oriented programming. By encapsulation, the separation of interface and business objects is achieved, and the distributed multilayer architecture is gradually implemented from interface and service separation, and the cross-platform of interface and business application is realized. Here is a solution to the general application to enterprise-level applications based on object-oriented programming ideas.
Part 5, Chapter 9 and 10 is a reference for object-oriented programming. Familiar with VCL Learning VCL is very helpful for proficiency Delphi. In view of the lack of the current VCL's insider information, this part provides to readers may be limited, but it is very difficult.
Accurately, this book is not written to "master", but written to programmers who want to change from RAD to OOP, and friends who want to learn OOP through Delphi. I think it is suitable as a relatively practical intermediate Delphi technology book. Therefore, in the text of the book, strive to be easy to understand, graphic, and carefully prepare a large number of sample programs (more than 50 trillion of the CD source code) for readers. The core OOP of this book is not against all aspects of Delphi. Read this book requires a certain Delphi foundation, and some specialized knowledge (such as: COM , etc.) also need to read the relevant books.
There may be some "master" to disappoint this book. I think I am not suitable for writing a book reading of "master", because I am not a master, I think I am always a newbie. Unlike other newcomers, I used Delphi's time longer, experience and experience a little more. So I found that the book is inappropriate, please readers to correct, don't help but feel more.
Netizen Xzh2000 is well said, "The life of a book is very important, if the author can spend heart blood often modify supplement, can achieve a classic!" Indeed, a good book needs to be revised multiple times to become a classic, so I am willing to listen to all readers' valuable suggestions and hope this book can constantly revise re-version.
[1] See the Delphi Help File "Delphi Language Reference". In this book, the author also called Delphi from Object Pascal.