C
Charles Law
This is going to seem like a basic OO question, but it comes up and bites me
every now and again.
Suppose we have a multi-tiered protocol to implement, what is the logical,
OO way to design the handler? For example, let's say that we have to
implement the ISO 7-layer protocol, or something like an Allen-Bradley
master-slave protocol. At the lowest layer we might only need to top and
tail the data being transported, such as DLE STX [data from network layer]
DLE ETX BCC.
[data from network layer] might comprise DST SRC CMD STS TNS [data from
application layer]
[data from application layer] might comprise FNC ADDR [data].
We could have a class for each layer, where each contains an instance of the
next layer down, e.g.
Public Class ApplicationLayer
Private m_NetworkLayer As NetworkLayer
End Class
Public Class NetworkLayer
Private m_LinkLayer As LinkLayer
End Class
Public Class LinkLayer
Private m_TransportLayer As TransportLayer
End Class
In the last case, TransportLayer could be a serial link implementation, or
some other type of communications handler.
Each layer would pass data on to the next layer down, and return results to
the caller; the next layer up.
Is this how other people would do it? I can't put my finger on why, but
there is something that just doesn't sit well with me about this method.
What if we want to dispense with the network layer? Do we have to change the
code in ApplicationLayer to keep a local LinkLayer instance? Wouldn't that
upset things a bit?
I suppose each local instance should be based on a common interface, so that
layers become, to some extent, interchangeable. Have I just answered my own
question?
What if we want to change the comms layer to something else: does that work
in the same way?
Also, the comms layer will probably need some kind of dynamic configuration,
such as baud rate, stop bits, etc. How do we configure this layer? The only
thing that has a handle to a TransportLayer object is the LinkLayer object,
but the LinkLayer knows nothing of baud rates and stop bits. Where does the
information come from? Do we have to pass it down the layers until the
object that understands the configuration gets it? That doesn't seem right
at all.
The same problem could occur in the network layer. An address is probably
required to ensure that the correct target gets the data, but where is this
address managed?
A lot of this is me just thinking out loud, but I would be interested in
other people's views. For example, is there a design pattern for this?
TIA
Charles
every now and again.
Suppose we have a multi-tiered protocol to implement, what is the logical,
OO way to design the handler? For example, let's say that we have to
implement the ISO 7-layer protocol, or something like an Allen-Bradley
master-slave protocol. At the lowest layer we might only need to top and
tail the data being transported, such as DLE STX [data from network layer]
DLE ETX BCC.
[data from network layer] might comprise DST SRC CMD STS TNS [data from
application layer]
[data from application layer] might comprise FNC ADDR [data].
We could have a class for each layer, where each contains an instance of the
next layer down, e.g.
Public Class ApplicationLayer
Private m_NetworkLayer As NetworkLayer
End Class
Public Class NetworkLayer
Private m_LinkLayer As LinkLayer
End Class
Public Class LinkLayer
Private m_TransportLayer As TransportLayer
End Class
In the last case, TransportLayer could be a serial link implementation, or
some other type of communications handler.
Each layer would pass data on to the next layer down, and return results to
the caller; the next layer up.
Is this how other people would do it? I can't put my finger on why, but
there is something that just doesn't sit well with me about this method.
What if we want to dispense with the network layer? Do we have to change the
code in ApplicationLayer to keep a local LinkLayer instance? Wouldn't that
upset things a bit?
I suppose each local instance should be based on a common interface, so that
layers become, to some extent, interchangeable. Have I just answered my own
question?
What if we want to change the comms layer to something else: does that work
in the same way?
Also, the comms layer will probably need some kind of dynamic configuration,
such as baud rate, stop bits, etc. How do we configure this layer? The only
thing that has a handle to a TransportLayer object is the LinkLayer object,
but the LinkLayer knows nothing of baud rates and stop bits. Where does the
information come from? Do we have to pass it down the layers until the
object that understands the configuration gets it? That doesn't seem right
at all.
The same problem could occur in the network layer. An address is probably
required to ensure that the correct target gets the data, but where is this
address managed?
A lot of this is me just thinking out loud, but I would be interested in
other people's views. For example, is there a design pattern for this?
TIA
Charles