Forum > Beginners

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

(1/4) > >>

pascal111:
لقد قرأتُ أنّهُ من أجل تطبيق البرمجة غرضيّة التوجّه في Lazarus أنّهُ يُمكنني أن أُعلن عن الأصناف بإحدى كلمتين مُسجلتين وهما object وclass ولكنّني علمتُ كذلكـ أنّ بينهما فروقاً وبدا لي أنّ النّسخة الرسميّة للأصناف والمطبّقة في بنية Lazarus والتي بها تمّ بناء وتنظيم الـ components هي نسخة الـ class فهل أنا مُلزم عند تطبيقي للبرمجة غرضيّة التوجّه أن أستخدم نُسخة class بدلاً من object أم أنّ لكل نُسخةٍ حالات إستعمالها أو تكادان أن تكونا مُتكافئتين وهما بحسب إختيار وتفضيل المُبرمج؟

google translate:

"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?"

lucamar:

--- Quote from: pascal111 on May 08, 2021, 01:25:39 am ---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 ---

I can't explain in detail now (it's quite late here) but they are quite different both in how they are used and in how they are implemented. And IMHO both have their use cases: most of the times you'll probably be using classes but (old-style) objects can be more simple and controlable in some cases, though that is now a little more "diluted" due to the availability of advanced records.

And, of course, the programmer's preferences play also a rôle here: some feel that classes were a step in the wrong direction and will swore by objects, while others think that object should be deprecated and only classes (and advanced records) should be used. To each his own, I guess :-\

pascal111:
من توضيحكـ إستبان أنّ هذا الموضوع مُتشابكـ ومُتشعّب ويحتاج إلى نوع من التفصيل ولكن ليس وقتكـ الحالي يسمح بذلكـ ،فسأنتظر عندما تكون في سعة من الوقت.

google translate:

"From your explanation, it is clear that this topic is intertwined and complex and needs some kind of detail, but your current time does not allow it, so I will wait when you are in a large amount of time."

Handoko:
You are free to use whatever you like. Here are the differences between advanced record, object and class:
https://forum.lazarus.freepascal.org/index.php/topic,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.

lucamar:
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.

Navigation

[0] Message Index

[#] Next page

Go to full version