F
Frank Munsberg
Hey,
I guess you all agree that layering software is a good idea but I'm at
a point where I'm not entirely sure which route to go (read: stay wtf
free).
Imagine something like a three layered application with a database,
business logic and ui layer for simplicity.
Now if I got the principle of dependency injection and inversion of
control correct then each layer exposes some interfaces which the
layer below it has to implement. That way you can just stack them on
top of each other and also replace some lower layer with mocked stuff
for testing and whatnot.
Some data object from the database layer implements the
"ibusinessobject" interface from the business logic layer. The object
can enter the business logic layer and is treated like it is of type
"ibusinessobject" but what about passing that one up to the ui layer
so it can be displayed to the user?
The ui layer should not know details of the layers below it so it
can't just handle objects of type "ibusinessobject" since it doesn't
know the interface. Now if one sticks to the plan the ui layer exposes
some interface to the business logic layer and the "ibusinessobject"
interface needs to implement lets say an interface named
"idisplayobject" from the ui layer.
now the actual implementation from the database layer directly
implements "ibusinessobject" and indirectly "idisplayobject" from the
ui layer which sounds creepy to me.
Is it a good idea to put a layer next to the whole layered cake and
name it something like data object layer, put the interfaces for the
data objects in it and have every layer that needs to know use the
interfaces from there?
Then you don't stack a chain of interfaces on top of each other and
the whole thing stays a bit cleaner.
I'm not sure if this leads to future problems of some sort but right
now the idea looks appealing to me as it would even work for more
layers so the cake can get bigger.
Maybe you can give me your thoughts about that.
Greetings
Frank
I guess you all agree that layering software is a good idea but I'm at
a point where I'm not entirely sure which route to go (read: stay wtf
free).
Imagine something like a three layered application with a database,
business logic and ui layer for simplicity.
Now if I got the principle of dependency injection and inversion of
control correct then each layer exposes some interfaces which the
layer below it has to implement. That way you can just stack them on
top of each other and also replace some lower layer with mocked stuff
for testing and whatnot.
Some data object from the database layer implements the
"ibusinessobject" interface from the business logic layer. The object
can enter the business logic layer and is treated like it is of type
"ibusinessobject" but what about passing that one up to the ui layer
so it can be displayed to the user?
The ui layer should not know details of the layers below it so it
can't just handle objects of type "ibusinessobject" since it doesn't
know the interface. Now if one sticks to the plan the ui layer exposes
some interface to the business logic layer and the "ibusinessobject"
interface needs to implement lets say an interface named
"idisplayobject" from the ui layer.
now the actual implementation from the database layer directly
implements "ibusinessobject" and indirectly "idisplayobject" from the
ui layer which sounds creepy to me.
Is it a good idea to put a layer next to the whole layered cake and
name it something like data object layer, put the interfaces for the
data objects in it and have every layer that needs to know use the
interfaces from there?
Then you don't stack a chain of interfaces on top of each other and
the whole thing stays a bit cleaner.
I'm not sure if this leads to future problems of some sort but right
now the idea looks appealing to me as it would even work for more
layers so the cake can get bigger.
Maybe you can give me your thoughts about that.
Greetings
Frank