R
RichB
I am trying to investigate design options for an application using seperate
layers and only passing data transfer objects (i.e. objects just of a data
struture to transfer data within the application) between the layers. If I
look at the Data Layer, I have a class which is a factory with for example a
"public Response Synchronise (iSycronisable dto)" method.
"iSyncronisable" is an interface, though there is nothing in the interface
to implement and the "Response" object is an abstract object with no
implementation (though of course this could be an interface aswell).
The reasoning behind this is that the Syncronise method can be called with
any object which derives from the iSyncronisable interface. The code in the
DAL factory creates a Data Access Object which knows all about the
interaction with the database for that type of Object and depending on
whether the object is new or existing decides to add new, update or delete
existing data. If a derived type is passed which was not understood by the
method, then an exception would be thrown.
The "Response" may then be different objects dependent on the action taken
and the iSyncronisable object passed. The calling class obviously needs to
then act on this object according to it's type.
Is this a reasonable thing to do or is it a no-no to use an interface or
abstract class to 'label' it's derived classes?
I would appreciate any advice or alternative suggestions.
Thanks, Richard
layers and only passing data transfer objects (i.e. objects just of a data
struture to transfer data within the application) between the layers. If I
look at the Data Layer, I have a class which is a factory with for example a
"public Response Synchronise (iSycronisable dto)" method.
"iSyncronisable" is an interface, though there is nothing in the interface
to implement and the "Response" object is an abstract object with no
implementation (though of course this could be an interface aswell).
The reasoning behind this is that the Syncronise method can be called with
any object which derives from the iSyncronisable interface. The code in the
DAL factory creates a Data Access Object which knows all about the
interaction with the database for that type of Object and depending on
whether the object is new or existing decides to add new, update or delete
existing data. If a derived type is passed which was not understood by the
method, then an exception would be thrown.
The "Response" may then be different objects dependent on the action taken
and the iSyncronisable object passed. The calling class obviously needs to
then act on this object according to it's type.
Is this a reasonable thing to do or is it a no-no to use an interface or
abstract class to 'label' it's derived classes?
I would appreciate any advice or alternative suggestions.
Thanks, Richard