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

  • Home
  • SEARCH
  • 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 6185287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:41:07+00:00 2026-05-24T01:41:07+00:00

I’ve have a library of data access objects and am tasked with designing the

  • 0

I’ve have a library of data access objects and am tasked with designing the logic layer. In this layer, I have access to the core data model, which I need to use to create Profile objects that can be passed to the UI for rendering.

Every object in the data model that needs an equivalent Profile object derives from the type Page. So ideally I need to write one method that accepts a Page as a parameter and returns a Profile. It’s not quite as simple as this, however, because the Profile objects are split into groups of Apps, which the user can enable.

I’ve tried various different approaches (and keep on deleting the whole lot and starting again!), but here’s the solution I’m trying at the moment:

public interface IApp
{
    //should be static, but interfaces cannot define static properties
    //so this instance property will return a private static field
    Dictionary<Type, IProfileCreator> Profiles { get; }

    //other things the App contains that isn't relevant to the profiles
}

public interface IProfile
{
    Page page { get; set; }
}

public interface IProfileCreator
{
    IProfile Create(Page page);
}

public class ProfileCreator<TProfile> where TProfile : IProfile, new()
{
    IProfile IProfileCreator.Create(Page page)
    {
        return Create(page);
    }

    public TProfile Create(Page page)
    {
        //constructor will have to be blank because of the new() constraint
        TProfile profile = new TProfile();
        profile.Page = page;
        return profile;
    }
}

I have to create 24 fairly big Profile classes for different pages, so I just want to make sure I’m doing it the best way I can before I start coding away. As you can see this design has a few flaws, but is there a better way of doing this? Has anyone tried a similar thing before (this situation can’t be that rare, can 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-24T01:41:07+00:00Added an answer on May 24, 2026 at 1:41 am

    Have a look at this Factoy PAttern (source):

      abstract class ProfileFactory 
        { 
            public abstract IProfile GetProfile(Page p); //Factory Method Declaration 
        }
    
    class concreteFactoryforProfile1 : ProfileFactory 
        {
        public override IProfile GetProfile(Page p) //Factory Method Implementation 
                { 
                    //data access stuff...
                    return new Profile() { Page = p }; 
                } 
        }
    
    class concreteFactoryforProfile2 : ProfileFactory 
        {
        public override IProfile GetProfile(Page p) //Factory Method Implementation 
                { 
                    //other data access stuff...
                    return new Profile() { Page = p };
                } 
        }
    
    
    interface IProfile 
        { 
            Page Page { get; set; } 
            //other properties can come here
        }
    
    class Profile : IProfile
        { 
            public  Page Page { get; set; }
            //other properties can come here
        }
    
    
    public class Test
    {
        void Main()
        {
    
            ProfileFactory[] objFactories = new ProfileFactory[2];
            objFactories[0] = new concreteFactoryforProfile1();
            objFactories[1] = new concreteFactoryforProfile2();
            foreach (ProfileFactory objFactory in objFactories)
            {
                IProfile objProfile = objFactory.GetProfile(this.Page);
                Page p = objProfile.Page;
            }
        }
    }
    

    Then two App might have the same type of Object, your implementation of the creation of the object will be done only once.

    If you need further details, please ask.

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

Sidebar

Related Questions

I have some data like this: 1 2 3 4 5 9 2 6
this is what i have right now Drawing an RSS feed into the php,
I have a JSP page retrieving data and when single or double quotes are
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS
I have a jquery bug and I've been looking for hours now, I can't

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.