Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have to create a communication protocol implementation.
For now, this protocol is based on RS232, but in the future we want to add a TCP/IP implementation of this protocol.

Now I'm looking for the best way of implementing this so adding new communication media is easy to integrate.

Are there some design patterns that are usefull? I have looked to the Adapter pattern and think this is an option but, maybe you have an better idea or article to refer to.

Regards,
Jerry
Posted

I am not sure if I understood you well, but you mixed things up here, you are talking about a communication protocol like TCP/IP or UDP and in the same time you want to implement it with a design pattern !?!! I think your worries should be bigger than that.
 
Share this answer
 
I would encapsulate the higher level functions in an interface with a method SendMessage and an event MessageReceived. You can then write concrete implementations for whatever communication layers you need.

You can then write a class with methods specific to your protocol, like GetWidgetCount, that use the interface. This is like the State pattern. To use a particular concrete implementation, you would just have to change the line:

C#
ICommunicate communicator = new TcpIpCommunicator();


Nick
 
Share this answer
 
No, we have an communication protocol to talk with our machines. It's working over a RS232 line right now.

But, we have to refactor this application and want to have the posibilitie to add another communication medium eg TCP/IP. But ofcource, we do not want to have the knowledge about Serial line or TCP/IP commands in our application.

Only the "Communication Layer" must be infacted when we add another communication media.

So that's why I want to find the best way of doing this. With a good design it must be possible :-)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900