Object programming in Delphi

xiaoxiao2021-03-06  47

In the process of participating in the interview, I asked the Delphi programmer for the application: "Pascal is the third generation of process-oriented programming language, but it turns into objects from the 1980s, you are currently in Delphi. What kind of views do you believe in object-oriented support? "I believe a lot of senior Delphi designers read the Delphi source code written by Borland. These source code is the good friend of these designers. I also read a lot of programmers with Delphi. Writing code. The code they wrote and the teacher taught me when the teacher of the Basic course gave an example code, a large pile of global variables, a lot of common functions. I calculate the number of times of calling these functions, 80% function Only calls only, that is, these so-called universal functions are not as universal when designing the author. This programming thinking is still a process-oriented programming in the 1970s. Perhaps this is also a reason for the framework of Delphi. Each time you create a form, you will automatically create a global variable of a form class (i.e., entity object) in unit files. This is actually a very bad implementation, although it is very simple and practical. : You don't need to program a program with a form, which is set to a main form. This instance is created in the Program file. The concept of object-oriented programming should have more detailed explanations in the professional programming course. If you want to feel object-oriented programming in an unconsciousness? It is recommended to use SmallTalk or Java. These two languages ​​are completely used for object-oriented thinking. There are many masters talk about object-oriented objects in Delphi. Technology to enhance development efficiency. I want to talk about the feelings of using Delphi to write code using Delphi programming: 1. I don't like to define a lot of variables: replaced by I define a class, put The associated variable is defined as the private variable of the class, and then move the process or function of these variables to the class, it will change it into a class. I found that I have a lot of benefits, I no longer need to define one The big pile of variables, I just need to declare an object variable. I don't need to take care of the relationship before working. These relationships are implemented in the class; if there is similar implementation in other places, I will It doesn't have to copy code as before. The copy code was used as a magic weapon by my colleague, but his program is too difficult to maintain, so that he will always say to rewrite these code. Of course, you can still These code encapsulates into a general function. After a while you may find that you have defined hundreds of universal functions in a public unit, do you remember them? How do they use it? Hey, to come from Cheng Bai In the thousand functions, I find the functions you want to do, and I have to make sure that they want the function. It is better to write a calculation. So there is a general function. So I have the following emotions: 2. I Almost do not write universal functions Instead, I put this function into the specific class. If you write some of the versatile functions, such as the API declaration function, it seems that there is no way to solve such problems. But I still I don't like it, I only declare the API function in the common unit, then introduce the API function into the class, so I don't have to look at Microsoft's words or understand the documentation. 3. Reconstruction How is it in delphi? If you follow the two principles above, after a while, you will find, 噫, how is this class so big? (MM like big ...) Take him Some. Let's take a look at One book, it seems to be what to do. Of course, there are some rules, you can try to do it. I prefer to refactor Because people's thoughts are always going forward. From I use 'one fingertra' to write the article, now write this shit, there are a lot of software programming or progress. I believe that many people can't reach the master. The level, one shot is a high level (I am also worshiped Unix creator, the operating system created at that time is still called the most advanced / stable; although Windows occupies the vast majority of terminals, it is currently From the high-end progress, but from the beginning of the architecture thought, it is impossible to be compared to UNIX). So, if the author of the book is said: I can't do it correctly, because the demand is always changing So I can always say lazy to the customer: What is your change? Say? More than 20% charge XX yuan. Well, is the XX yuan too little? It depends on your posture, I am more Confidence, so the price is relatively low ..... 4. Design mode? I have seen it all , I don't understand it, so ... I also see the master's work. It seems that I didn't say object programming. ? Oh, right, a little bit of the title. I am thirsty, drink the water and then say. Delphi actually changed the PASCAL language into objectpascal language for object-oriented programming; see the source code of VCL Framework,

The use of object-oriented programming technology, carefully asked these source code, and slowly you will understand the benefits of object-oriented programming, if you can go further, you can also give a back to the three, and associate it. Whether it is two or three layers, or multiple layers. Whether it is a current intermediate programming, service-oriented, component programming, in fact, based on object-oriented programming. Object-oriented programming is the most basic idea, just like people's walking. I can't imagine how people who walked will run, go to jump? I don't know if you can think of it? In fact, my title is too big, I just want to talk about my feelings for Delphi object-oriented programming. For Delphi and VCL Framework, I can only be counted as a door.

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

New Post(0)