Re: How implement an abstract class?



On Thu, 2003-08-14 at 14:33, Antonio Santiago wrote: 
Hello,

Hello

I want to implement an abstract class with their own attributs that
inherit all her subclasses, and her own methods, some implemented and
somo not).

Vehicle <----- Car

If I create a class Vehicle and a class Car, there is nothing to avoid
someone create a simple Vehicle's object, and then I would have an
instance of an abstract class.

Of course it is very important that a user cannot create an instance
of an abstract class. When you register your object using
g_type_register_static in your vehicle_get_type you have to specifiy
the G_TYPE_FLAG_ABSTRACT as the last paramater : eg:

g_type_register_static (G_TYPE_OBJECT, "Vehicle", &this_info,
G_TYPE_FLAG_ABSTRACT);

Also do not provide vehicle_new() and cleary document that Vehicle
is an abstract class :-) You should be fine and users won't be
able to instantiate your astract class Vehicle.

Some ideas.

Thanks.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]