Exforsys

Online Training

Common Interface to I/O

This is a discussion on Common Interface to I/O within the Software Patterns forums, part of the Testing category; Hi, I'm new to software patterns and I am trying to apply it to my C++ project. For my ...


Go Back   Exforsys > Testing > Software Patterns

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-26-2005, 04:18 PM
fernandez.dan@gmail.com
Guest
 
Posts: n/a
Common Interface to I/O

Hi,

I'm new to software patterns and I am trying to apply it to my C++
project. For my project I have a class called Protocol, I'm just
playing with my own protocol. At the moment my Protocol class can write
to two different I/O.

I want to make my Protocol not care about the type of I/O just to read,
write, open, and close the I/O. It shouldn't matter if it the network
or usb.

At the present, I created an abstract I/O class that contains read,
write, open, and close. Then I created two I/O classes, CNetwork and
CUSB that inherit from this abstract class and define the
implementation.

Here is an abstract example how I create my io and pass it to my
protocol class

abstractIO* m_io;
m_io = new CNetwork(...); // or new CUSB( )
CProtocol protocol(m_io);


I was wondering what other technique can be used to make my Protocol
class more indepedent on the I/O. Thanks

Danny

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 08-27-2005, 04:42 AM
Nick Malik [Microsoft]
Guest
 
Posts: n/a
Re: Common Interface to I/O

you did a fine job of using the strategy pattern to encapsulate the basic
objects that you intend to use.

You may want to look at using a factory pattern to encapsulate the creation
of your object as well, so that the calling code is not bound to the static
object that represents the specific I/O method that your configuration would
indicate.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
<fernandez.dan@gmail.com> wrote in message
news:1125083906.263857.157390@g47g2000cwa.googlegroups.com...
> Hi,
>
> I'm new to software patterns and I am trying to apply it to my C++
> project. For my project I have a class called Protocol, I'm just
> playing with my own protocol. At the moment my Protocol class can write
> to two different I/O.
>
> I want to make my Protocol not care about the type of I/O just to read,
> write, open, and close the I/O. It shouldn't matter if it the network
> or usb.
>
> At the present, I created an abstract I/O class that contains read,
> write, open, and close. Then I created two I/O classes, CNetwork and
> CUSB that inherit from this abstract class and define the
> implementation.
>
> Here is an abstract example how I create my io and pass it to my
> protocol class
>
> abstractIO* m_io;
> m_io = new CNetwork(...); // or new CUSB( )
> CProtocol protocol(m_io);
>
>
> I was wondering what other technique can be used to make my Protocol
> class more indepedent on the I/O. Thanks
>
> Danny
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-27-2005, 10:19 PM
fernandez.dan@gmail.com
Guest
 
Posts: n/a
Re: Common Interface to I/O

Thanks for the input Nick,

I was looking at the factory pattern to create my object. Also I was
also looking at using a smart pointer that the factory would
instantiate for the caller. It would be something like this

IoPtr<abstractIO> m_io( new CNetwork(..) );

for my Network I/O. The Factory class would determine which to
instantiate the CNetwork or CUsb eventually giving me something like
this

IoPtr<abstractIO> m_io = Factory.CreateIO(/*field to determine IO*/);
CProtocol protocol(m_io);

Thanks for any input.

Danny

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 11:14 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.