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 370125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:59:15+00:00 2026-05-12T13:59:15+00:00

I am new to design patterns and now I want to implement the Strategy

  • 0

I am new to design patterns and now I want to implement the Strategy patern. Here’s my code:

namespace StrategyPattern
{
    public interface ISendBehavior
    {
        void Send();
    }

    public class SendAppointment : ISendBehavior
    {
        public void Send()
        {
            // send item
        }
    }

    public class SendTask : ISendBehavior
    {
        public void Send()
        {
            // send item
        }
    }

    public class SendItem
    {
        ISendBehavior _sendBehavior;

        public SendItem(ISendBehavior sendbehavior)
        {
            _sendBehavior = sendbehavior;
        }

        public void Send()
        {
            _sendBehavior.Send();
        }
    }

    /* CALL */

    public class Aanroep
    {
        public void Verzenden()
        {
            SendItem app = new SendItem(new SendAppointment());
            app.Send();
        }

    }
}

In the method Send in the class SendAppointment the item will be send. My question is, do I have to connect to the database in this class? If so, then I also have to connect to the database in SendTask. But at this point I am repeating myself right? So if a connection string changes, i have to modify this in every class. How can I solve this problem?

  • 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-12T13:59:16+00:00Added an answer on May 12, 2026 at 1:59 pm

    How about initializing each implementor of ISendBehavior with yet another object that’s responsible for the database connection?

    Your Verzenden()-implementation would be something like

    IDatabaseConnection connection = new DatabaseConnection();
    
    SendItem app = new SendItem( new SendAppointment( connection ) );
    

    and your ISendBehavior.Send() would be implemented like this

    _databaseConnection.Send( ... ); // fill behavior-specific information here (perhaps with properties)
    

    This way, you can reuse that IDatabaseConnection for any other classes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm gonna implement a new design / website structure for a customer, but I
I am new to web-design. I want to set the page-width so that it
I am relatively new to db design, so any help here would be appreciated.
I am new to the design patterns. I have used it on the frameworks
I'm working my way through 'head first design patterns' and want to use this
i am a newbie to the design patterns and here is my question if
I'm kind of new to the design patterns concept. C# is my primary programming
I'm creating a small program with some design patterns, and I'm trying to implement
I am new to the MVVM design pattern, and I am working on a
I'm pretty new to WPF and using the MVVM design pattern. To help learn

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.