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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:45:33+00:00 2026-06-10T08:45:33+00:00

I have SaveManager Abstract class and my concrete classes TVSaveManager, DataSaveManager and VoiceSaveManager implementing

  • 0

I have SaveManager Abstract class and my concrete classes TVSaveManager, DataSaveManager and VoiceSaveManager implementing SaveManager Abstract class.

List<SaveManager> lstPrdSaveManager;

        public SaveResponseModel SaveProducts(SaveProductsRequest objSaveProductsRequest)
        {
            SaveResponseModel saveResponseModel = new SaveResponseModel();

            lstPrdSaveManager = SaveManagerFactory.GetSaveManagers(objSaveProductsRequest, saveResponseModel);

            lstPrdSaveManager.ForEach(saveManager =>
                {
                    saveResponseModel = saveManager.MapAndSaveProduct();
                });


            return saveResponseModel;
        }

Factory class will decide which manager to create and send us the list. I will loop thru the list and invoke the common interface ‘MapAndSaveProduct’ that every concrete classes will adhere. I guess more or like a strategy pattern.

But the thing is all the concrete savemanage’s MapAndSaveProduct method return type is different. TVResponse for TvSaveManager and DataResponse for DataSaveManager and so on. So i created SaveResponseModel class to club all the return types (I am passing SaveResponseModel to factory so that it will get passed to all concrete savemanager class’s constructor. Individual class will set the desired property., like TvSaveManager -> saveResponseModel.TvResponse). I get desired result and code looks clean.

Questions are,
1) Is it the correct way to use this pattern when we have different type?
2) If concrete class have different types, should not we use strategy pattern?
3) Should I approach to different design pattern in this case. if yes which one?

  • 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-06-10T08:45:35+00:00Added an answer on June 10, 2026 at 8:45 am

    You’ve got a combination of Strategy and Visitor in a single group of methods; this is absolutely OK. You could separate them out by giving the responses a common interface, and adding a visitor to it for harvesting the right response. This would apply two patterns in sequence, rather than applying both at the same time.

    interface IResponseVisitor {
        void VisitTvResponse(TvResponse r);
        void VisitDataResponse(DataResponse r);
    }
    interface IResponse {
        void Accept(IResponseVisitor v);
    }
    class TvResponse : IResponse {
        public void Accept(IResponseVisitor v) {
            v.VisitTvResponse(this);
        }
    }
    class DataResponse : IResponse {
        public void Accept(IResponseVisitor v) {
            v.VisitDataResponse(this);
        }
    }
    

    Now all your MapAndSaveProduct implementations could return the common IResponse. You could collect them all, and then go through them with an implementation of IResponseVisitor, and do what you need for each type inside the corresponding Accept method.

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

Sidebar

Related Questions

Let's use a quite plain example with employees and company(-ies) . public abstract class
I have this servlet - @WebServlet(/CreateNewPersonServlet) public class CreateNewPersonServlet extends HttpServlet { private void
I am creating a employee wage system. I have an abstract Employee class. WageEmployee
I have a form using this model: public class MyModel { public User SalesManager
I have a State class defined like this: Public Class State Public Property StateId
have written this little class, which generates a UUID every time an object of
**Have it working now. I forgot to populate the Array List. How embarrassing. I'm
I have extended threading.Thread - my idea is to do something like this: class
I am making a game and have started to work on a class called
I have the following StateManager: Lead.StateManager = Ember.StateManager.extend initialState: 'notParsing' notParsing: Ember.State.create startParsing: (manager,

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.