Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6765851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:45:41+00:00 2026-05-26T14:45:41+00:00

I’m working my way through ‘head first design patterns’ and want to use this

  • 0

I’m working my way through ‘head first design patterns’ and want to use this in practice immediately.
I’m writing a piece of code that connects an application with other applications. In fact, I need to generate an e-mail containing an XML file and send it via e-mail. But other stuff might be required in the future.

Thus, I identified ‘the things that change’:
– The data for the transmission
– The means of transmitting (could be e-mail, but could be FTP or webservice for another data-exchange)

So, I:
– Created an abstract class DataObject
– Created an interface ITransmissionMethod
– Created an dataExchange abstract class:

  abstract class DataExchange<T,U>
    {
        private T DataObject;
        private U SendMethod;
    }

And SendViaMail is like

class SendViaMail : ISendMethod<System.Net.Mail.Attachment>
{
    public override void Send(System.Net.Mail.Attachment dataItem)
    {
        throw new NotImplementedException();
    }
}

Now – I can create classes like:

class MyExchange : DataExchange<MyDataObject,SendViaMail> { }

What do you think about this approach? Now what I would really like to do is Create an abstract method in DataExchange that should look something like

private abstract [the type of the T in ISendMethod<T>] PrepareObjectForSending(T dataObject) {
}

Visual Studio would force me to implement a method like:

private abstract System.Net.Mail.Attachment PrepareObjectForSendingMyDataObject dataObject) {
// Serialize XML file and make it into attachment object
}

Wouldn’t that be sweet? But what do you guys think about this approach? In the future, people can create new dataObjects and new sendmethods and the code would still work. What I’ve been trying to do is: program against interface and extract changing parts. How about it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:45:41+00:00Added an answer on May 26, 2026 at 2:45 pm

    That would work, but you could separate concerns even more. Here is just another version – make DataExchange to be very simple and delegate real work to workers:

    class DataExchange<TDataObject, TTransmissionObject>
    {
        IConverter<TDataObject, TTransmissionObject> conterver;
        ISendMethod<TTransmissionObject> sender;
    
        public Send(TDataObject dataObject)
        {
            TTransmissionObject tro = conterver.Convert(dataObject);
            sender.Send(tro);
        }
    }
    

    Converts would just convert data objects to objects suitable for transmission:

    class DataToAttachmentConverter : IConverter<DataObject, Attachment>
    {
        Attachment Convert(DataObject) { }
    }
    class DataToXmlConverter : IConverter<DataObject, XmlDocument>
    {
        XmlDocument Convert(DataObject) { }
    }
    

    Senders would only send.

    class MailSender : ISendMethod<Attachment>
    {
        void Send(Attachment) {}
    }
    class FtpPublisher : ISendMethod<XmlDocument>
    {
        void Send(XmlDocument) {}
    }
    

    Putting all together:

    var exchanges = new [] {
          new DataExchange<DataObject, Attachment>( new DataToAttachmentConverter(), new MailSender()),
          new DataExchange<DataObject, XmlDocument>( new DataToXmlConverter(), new FtpPublisher())
    };
    
    foreach(var ex in exchanges)
        ex.Send(dataObject); //send as an attachent and put to ftp site.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.