Forum > Beginners

which to use "object vs class"? [SOLVED]

<< < (2/4) > >>

As a beginner, if you are writing code for the Turbo/Free Vision framework, or work on other old TP codebases, use object.

In all other cases use (delphi styled) classes.


--- Quote from: Handoko on May 08, 2021, 04:28:52 am ---You are free to use whatever you like. Here are the differences between advanced record, object and class:,30686.msg298518.html#msg298518

The differences are too technical for most users to understand. Class is considered as the better version of object especially in the old operating system era, for example DOS, which had very limited stack memory for program to run. Object is still maintained but there will be no or little new features added.

But for performance reason, some programmers still use object nowadays. Class needs to allocate memory from heap, which is a very complex process. Object allocates memory from stack, so it is faster.

Normally you should use class, unless you have reasons to use the other.

--- End quote ---

ذهبتُ إلى الرابط الذي زوّدتني به ووجدت من المقارنة بين السجلات ونوعي الأصناف أنّ الفروق تقنيّة حقّاً وهي مفاهيم برمجيّة مُتقدمة أي أنّهُ للمُبتدئين لا يُوجد فرق ملحوظ أو مفهوم ولكن الأمر سيتضح بعد دراسة مُتقدمة وبعدها يستطيع المُبرمج المُبتدئ أن يُحدد أي نسخةٍ يُريدها ،لا يُمكن إتخاذ قرار إلا بعد الإحاطة بمفاهيم الفروق التقنية بين السجلات ونوعي الأصناف.

google translate:

"I went to the link that you provided me with and found from the comparison between the records and the two types of items(classes) that the differences are really technical, which are advanced programming concepts, meaning that for beginners there is no noticeable difference or concept, but the matter will become clear after an advanced study and then the novice programmer can determine which version he wants, no decision can be made Except after understanding the concepts of the technical differences between the records and the two types of items(classes)."


--- Quote from: lucamar on May 08, 2021, 12:11:52 pm ---A rather thorough discussion of the two models can be found in the topic: Object in FPC vs class in objFPC.

Particularly, 440bx's answer contains a very nice summary of the pros and contras of each of them from a person that knows them well.

--- End quote ---

@damieiro in the link considers the two models quite similar, but they have some similarity, especially some technical points.

If I'm not mistaken, you are a beginner in oop concept.

Just take the classes approach and forget about old style objects. You don't need this confusion.


--- Quote from: pascal111 on May 08, 2021, 01:25:39 am ---"I have read that in order to implement the programming for the purpose of orientation (OOP) in Lazarus that I can announce "declare" the classes by one of two registered words, object and class, but I also learned that there are differences between them, and it seemed to me that the official version of the classes applied in the Lazarus structure in which the components were built and organized is the version of the class. Am I obligated, when I apply for purpose-oriented programming (OOP), to use the class version instead of the object, or does each version have its use cases or are almost equivalent, and they are according to the choice and preference of the programmer?"

--- End quote ---

While we don't declare TP-style objects as deprecated like Delphi did, they are essentially in "maintenance mode". So if you want to take advantage of newer language features, it's more likely that the Delphi-style classses will get them than TP-style objects.

Also if you want to interact with Lazarus' LCL you pretty much must use Delphi-style classes.


[0] Message Index

[#] Next page

[*] Previous page

Go to full version