Brian,
| My first concern if I start adding properties to the base Message that
might
| not be supported by the clients is that every time I want to create a new
| message type, I have to add the additional properties to Message and write
| HasX methods for all of my other Message subclasses.
Yes that's a valid concern, however I find its better to only couple to
Message, rather then couple to each specific class.
Another option I thought about, but have not worked out the specifics is to
introduce interfaces for each "part" you may be going after.
Incomplete example:
Public Interface IBody
Property Body As String
End Interface
Public Interface ISubject
Property Subject As String
End Interface
Then BodyMessage & SubjectBodyMessage would implement the interfaces:
Public Class BodyMessage
Inherits Message
Implements IBody
End Class
Public Class SubjectBodyMessage
Inherits Message
Implements IBody
Implements ISubject
End Class
Then would check for the above interface & act appropriately
Private Function GetSubjectText(message as Message) as String
If TypeOf message Is ISubject Then
Return DirectCast(message, ISubject).Subject
Else
Return message.ToString()
End If
End Function
The Interface itself then acts as the HasMethod.
Your form code is only coupled to the interfaces & not to the specific types
of messages.
I would expect this method has its own pluses & minuses also.
Hope this helps
Jay
| "Jay B. Harlow [MVP - Outlook]" wrote:
| > | wouldn't make much sense to add a subject method to the BodyMessage
class
| > | since it doesn't represent a message with a subject.
| > I would put both Subject & Body as Overridable in Message, as Messages
may
| > have a Subject or they may have a Body, also its the "key" to ensuring
| > Message is as generic as possible. I would consider adding HasSubject &
| > HasBody properties, ala the System.IO.Stream class. Not all specific
Stream
| > classes are seekable (NetworkStream for example). Although Stream has a
Seek
| > method, NetworkStream.Seek throws an NotSupportedException if you
attempt to
| > call it, the NetworkStream.CanSeek returns false...
|
| Thanks for contributing thought and time to this. I appreciate it.
|
| My first concern if I start adding properties to the base Message that
might
| not be supported by the clients is that every time I want to create a new
| message type, I have to add the additional properties to Message and write
| HasX methods for all of my other Message subclasses.
|
| For example, say I have two forms in different applications that can
receive
| and display these messages. One form supports messages with subject and
body
| and the other supports messages that have subject and body and optionally
an
| object that is used to trigger some action by the program. If form #1
gets a
| message with subject, body, and an object, it should behave nicely and
| display the subject and body and ignore the object (it doesn't know what
to
| do with it anyway). Form #2 should display the subject and body and work
| with the object. But it seems incorrect to add the object property/method
to
| the Message class because it is not a part of all messages, only a certain
| type.
|
| Obviously, if each application only received messages that they could 100%
| support this would be much easier. I am trying to allow applications to
| handle messages they are not able to support 100% however because I
believe
| if Application A sends a message to Application B it is better for the
user
| of B to get *something* rather than *nothing*.
|
| > My concern is introducing unbounded recursion. Message.Body calls
ToString,
| > which may call Message.Body, which calls ToString... Right now I'm not
| > seeing an easy way to avoid that, I would need more details on what you
are
| > doing to know how or if you can avoid it... The HasBody & HasSubject
| > properties may help here...
|
| That would be icky. The only defense I can offer to that is that I
| generally don't code that way. Properties may refer to variables, nothing
in
| the class depends on ToString.
|
| Thanks for your suggestions,
| Brian