Non-ugly ways to implement a 'static' class or namespace?

Ali Çehreli acehreli at yahoo.com
Mon Jan 30 17:00:20 UTC 2023


On 1/29/23 22:09, RTM wrote:
 > On Saturday, 28 January 2023 at 23:19:35 UTC, ProtectAndHide wrote:
 >
 >> That is, you can do OOP without classes
 >
 > How so?

OOP is about putting objects (data) and behavior (functions) together.

 > Every OOP definition includes classes

OOP is possible in C, which does not have classes:

   void sing(Animal * animal);

That top-level sing function will do something like this:

   animal->sing(animal);

Every object has their own sing function pointer as a member. (Or one 
can go to a vtbl pointer approach with different pros and cons; I used 
all of this as an interview topic at some point.)

Programming languages just make it easy.

 > (encapsulation + inheritance).

Encapsulation is available even in C as well. Inheritance can be 
achieved manually.

And I used C just because it does not provide any special OOP features.

Ali



More information about the Digitalmars-d-learn mailing list