Marking a class as abstract...

Posts   
 
    
stef
User
Posts: 28
Joined: 14-Jun-2005
# Posted on: 08-Nov-2005 04:55:01   

If I mark a class in the designer as being an abstract class, what is the effect in the generated code?

I've been putting together my first test code using the new inheritance features and I don't see what this flag does. The class I mark as abstract is generated as a public class and is also included in the entity factory - I would have thought that I shouldn't be able to create instances of abstract classes? confused

What am I missing? Thanks, Stef

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39897
Joined: 17-Aug-2003
# Posted on: 08-Nov-2005 08:43:44   

stef wrote:

If I mark a class in the designer as being an abstract class, what is the effect in the generated code?

I've been putting together my first test code using the new inheritance features and I don't see what this flag does. The class I mark as abstract is generated as a public class and is also included in the entity factory - I would have thought that I shouldn't be able to create instances of abstract classes? confused

What am I missing?

The constructor is internal. This means that you can't create an instance yourself, but the generated code can internally for some operations, if it requires that. This is for example the case if you have employee <- manager <- boardmember and employee is abstract. If you fetch a collection of 'employees' it will use the employee fields to produce the first query, which is easiest with a dummy entity and using its fields, hence the internal constructor.

Frans Bouma | Lead developer LLBLGen Pro
stef
User
Posts: 28
Joined: 14-Jun-2005
# Posted on: 08-Nov-2005 20:38:14   

Thanks Otis, A couple of unit tests later and I can't create an abstract class from an external assembly using new but I can using the GeneralEntityFactory, e.g.

CampaignEntity campaign = GeneralEntityFactory.Create(EntityType.CampaignEntity) as CampaignEntity;

Since it's only the constructors that are marked as internal, using the factory provides a fully useable class instance outside the assembly.

Should the abstract classes be available through the factory?

Cheers, Stef

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39897
Joined: 17-Aug-2003
# Posted on: 09-Nov-2005 11:06:50   

stef wrote:

Thanks Otis, A couple of unit tests later and I can't create an abstract class from an external assembly using new but I can using the GeneralEntityFactory, e.g.

CampaignEntity campaign = GeneralEntityFactory.Create(EntityType.CampaignEntity) as CampaignEntity;

Since it's only the constructors that are marked as internal, using the factory provides a fully useable class instance outside the assembly.

Should the abstract classes be available through the factory?

The runtime uses the factory to create an instance of the entity which is marked as abstract, to be able to produce hierarchical queries, however that's code in the runtime code. I couldn't find a way to really stop it or work around it and generate the entity class(es) as 'abstract' instead of normal classes with an internal constructor.

I'll do some more investigation in this matter to see how I can avoid public instances.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39897
Joined: 17-Aug-2003
# Posted on: 10-Nov-2005 13:40:58   

The type of the inheritance hierarchy is retrieved from the entity instance created with the factory. This type is then used to retrieve additional information for type filters etc. in collection fetches. The inheritance hierarchy type isn't available through the factory, which should have been, as that would have solved the need for an instance. I've to make several deep changes to make this possible, and I'm not sure if that's in everyone's interest with the current version. It's a mistake in the interface design for entityfactories, though changing the interface now can lead to all kinds of incompatibility problems...

Frans Bouma | Lead developer LLBLGen Pro
stef
User
Posts: 28
Joined: 14-Jun-2005
# Posted on: 13-Nov-2005 23:46:00   

Thanks for following this up Frans, it's good to understand the why.

Cheers, Stef

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39897
Joined: 17-Aug-2003
# Posted on: 14-Nov-2005 10:58:53   

stef wrote:

Thanks for following this up Frans, it's good to understand the why.

Cheers, Stef

simple_smile In v2.0 I'll redesign the architecture to have true abstract classes.

Frans Bouma | Lead developer LLBLGen Pro