Design problem
Hello everyone ,
i'm new at OOP and i discovered yesterday that i can't use static functions in inheritance (with virtual,abstract or override) so i'm kind of stuck.
i need to design a 3 layered application (three classes):
1 ) GUI Layer
--------
2 ) Application layer
--------
3 ) Communication layer
Sending Data:
When the user pushes a button, the GUI layer collect data from the Form into a struct and sends it to the application layer . this layer prepares a protocol and sends it into the communication layer for sending it through the USB.
receiving data:
The communication layer receives a protocol and sends it to the Application layer which prepares a struct of the important data in the protocol ( peals off the Header footer and CRC ) and sends a prepared struct into the GUI layer which present the details of the struct on the GUI.
what is the best way to implement this design ?
i though of a way to design it :
all of the three layers will only have static functions. The purpose of that is to make each layer use the next layer functions without creating object from the layer classes. for example, the application layer will call :
Communication.SendData(ProtocolString); when sending data and
GUI.Present(DataStruct); when receiving data.
i dont think it's a good design because all of the layer class functions and variable will be all static. and that inside the layer class i can't use inheritance cause the functions has to be static.
i will be glad to recieve book recomandations that describes of how to deal with designs like these ( or links maybe? ), so i can upgrade myself.
maybe design pattern will help ?
How would you implement such an application?
[1843 byte] By [
asafaa] at [2007-11-19 18:36:33]

# 1 Re: Design problem
I am not sure if you understand the concept of multi-layered or multi-tier application. Those layers/tiers are not simple classes. If this is what you mean, you are conceptually wrong about them, if this is not what you mean, then I am sorry, but I couldnt understand your design goal.
Basically, you have different assemblies just to group same layered classes into one. You have various classes that have their interfaces defined in such a way that their objects can be used by the layers above.
First comes the UI layer - there you will have a group of forms, web pages, whatever UI you are using for your application. The code-behind forms a part of this.
Then you will have an Application layer, that will constitute classes that can instantiated (or in general terms, used) from the UI layer and then they interact with any other layer be it backend database or database layer.. or whatever.. This basically would contain most of your business logic.
I am not quite sure what your Communication layer is supposed to do. May be it's the one that the UI works with, with an intermediate layer - Application.
I am very uncomfortable with how you make these layers as classes with static and only static members. Do a google search to read up on n-tiered architectures. Regards.
# 2 Re: Design problem
The main design goal is to separate layers as much as possible. That way layers can be developed independently. For example "Communication layer" shouldn't know nothing about the data itself except of its size and destination. As the oposite, Application layer shouldn't know nothing about protocol used by communication layer (only maybe destination/source info:cool: ), so it shouldn't "peals off the Header footer and CRC" because it should receive data without them.
There is no need to use only static functions. U could separate layers into clasess and:
1) Application layer: (busines logic layer) should manage data logic itself. It reads configuration files and prepares envinroment (open connections [comunication layer], views [GUI layer]etc.). So for example it can have one or more global communication objects and one or more data objects.
2) GUI Layer. Consists of one or more views of each data object (or collection of objects). Changes in data objects propagates (events) to corresponding views. GUI changes simply involves modifications of data by methods of that object.
3) Communication layer simply gets data object and destination info. It adds some headers/CRC and send data. Or receives data strips it from that additional info and passes it to data layer (event at which data layer is subscribed to). Changes in data layer triggers corresponding views to be refreshed.
Hope that it helps.
Krzemo.
Krzemo at 2007-11-9 11:20:01 >

# 3 Re: Design problem
Thanks exterminator,
You are correct , I'm uncomfortable with my design of the static members too.
The communication layer is a class that responsible of sending data through com port,USB or any other device i'll choose in the future.
When the application layer wants to send data, it only writes Communication.Send(Struct);
Later, i will be able to write the Communication layer with different send() codes according to my desire. ( i will only have to rewrite Send() to change the program from sending through COM1 to send through the USB, Net or whatever). That is the purpose of the communication layer.
I devide the application into layers to magnify the purpose of each class, i didn't know the layer design could be so difficult. i believe you agree with me that the Send() and Read() functions that works with the com ports shouldn't be located in the GUI class, then i invented the need for a communication layer. am i on the right track ?
you are right about the UI layer.
The application layer prepares a string of data that needs to be sent through the Communication layer and starts a timer to wait for acks from the Communication layer, that is her purpose.
asafaa at 2007-11-9 11:21:00 >

# 4 Re: Design problem
YES YES YES! , thanks Krzemo,
You logged on my exact desine and described it even more clearly than i did.
after my desine is clear ,i can be more specific with my question :
How does each layer calls the next layer function if the next layer function is not static ?!
How does the application layer calls the Communication layer Send() function if the Send() function is not static ? ( i can't just call Communication.Send() ). can you be more specific on that subject cause this is exactly my problem.
you mentioned events : "(event at which data layer is subscribed to)"
Does the layers communicate with each other by events ?
I have to remind that when sending data the layers go down : UI->Application->Communication and when receiving data the layers go up : Communication->Application->GUI.
(you are right , the communication layer should do the peal of the protocol)
asafaa at 2007-11-9 11:22:04 >

# 5 Re: Design problem
Events or multicast delegates are powerfull tools for inter components communications. They can help to separate design.
Does the layers communicate with each other by events ?
By events or by methods.
For example: each view has only one data object (or collection of data objects which stands for one composite data object), but in the same time this data object can be associated with many views. So if view wants to comunnicate to application layer it simply fires methods of that object (because reference to data object is kept in view object - passed to a view in view creation process). View subscribes to events in data object so it can be refreshed when data changes.
Krzemo at 2007-11-9 11:23:03 >

# 6 Re: Design problem
Thanks Krezmo, you helped me alot.
Do you have a link or example of such communication between layers?
of how to subscribe view to events of data object or "firing methods" of an object ?
it would help me alot.
asafaa at 2007-11-9 11:24:02 >
