Hiding constructors

Posts   
 
    
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 30-Nov-2004 08:34:51   

Greetings all,

I am using the "Adapter configuration file with sub-classes" to generate the sub-class entities. In each of these sub-class entities I am exposing a set of standard services which include a NewSubClassEntity routine that returns a new instance of the sub-class entity. Since I want to force the UI to use my service routine and not a constructor, I need to make all the constructors in the sub-class entities as "private" or "protected". I am worried that this could break LLBL's framewrok functionality in some hidden way. Will it be safe to hide the constructors in this manner without any side-effects?

OMAR

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 30-Nov-2004 10:28:32   

Why didn't you move the special constructor functionality to the factories? (and throw a not-implemented exception in the normal constructors and create an internal constructor for usage with the factories)

Xml deserializing code (ReadXml()) works with the normal constuctors (no parameters).

Frans Bouma | Lead developer LLBLGen Pro
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 30-Nov-2004 15:41:38   

FRANS.. I don't think I understand your idea flushed

the following is one service routine I have in a derived-class (GLMoneyWithdrawal is a sub-class of GLMoneyWithdrawalEntity)

        Public Overloads Shared Function NewGLMoneyWithdrawal() As GLMoneyWithdrawal
            Return New GLMoneyWithdrawal
        End Function

Ofocurse I would have some extra logic in this routine for defaults, security and others...

what I am doing now is that I changed the scope of all constructor routines in GLMoneyWithdrawal to "Protected" and some to "Protected Friend" (so that the factory methods can access these constructors)

What is a better approach than this one ?

OMAR

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 30-Nov-2004 16:10:24   

You don't have factory classes for your derived entity classes? Because these should be used to create a new instance of a given type. (imho), as these are also used to create new instances when fetching a collection of entities.

So the factory calls the protected friend (internal) constructor, while a developer can't do that and has to use the factory for example:

Dim newGLMoneyWithdrawal As GLMoneyWithdrawal newGLMoneyWithdrawal = GLMoneyWithdrawalFactory.Create()

And GLMoneyWithdrawalFactory is a subclass of GLMoneyWithdrawalEntityFactory. So when you do: Dim withdrawals As New EntityFactory(New GLMoneyWithdrawalFactory()) adapter.FetchEntityCollection(withdrawals, Nothing)

you'll get the proper classes with the proper initialization.

Frans Bouma | Lead developer LLBLGen Pro