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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:05:53+00:00 2026-05-25T02:05:53+00:00

The design problem is as follows, actual problem consists of 2 modules. Module 1

  • 0

The design problem is as follows, actual problem consists of 2 modules.

Module 1 classes (External Assembly)

abstract class Letter
{
    private int _id;
    protected Letter(int id) { _id = id; }

    public abstract string Val { get; }
}

class LetterA : Letter
{
    public LetterA(int id) : base(id) {}

    public override string Val
    {
        get { return "A"; }
    }
}

class WordWithALettersOnly
{
    public IList<LetterA> ALetters { get; set; }
}

Module 2 classes

class LetterSmallA : LetterA 
{
    public LetterSmallA(int id) : base(id) {}
    public override string Val
    {
        get { return "a"; }
    }
}

class WordWithSmallALettersOnly : WordWithALettersOnly
{
    private IList<LetterSmallA> _aLetters;
    public new IList<LetterSmallA> ALetters
    {
        get { return _aLetters; }
        set
        {
            _aLetters = value;
            if(_aLetters != null)
                base.ALetters = value.Cast<LetterA>().ToList(); // <-- reference lost
        }
    }
}

class Program
{
    static void Main(string[] args)
    {
        var smallAWordOnly = new WordwithSmallALettersOnly();
        smallAWordOnly.ALetters = new List<LetterSmallA>(){new LetterSmallA(1)};
        Console.WriteLine("d : " + smallAWordOnly.ALetters.Count); // --> 1
        Console.WriteLine("b : " + ((WordwithALettersOnly)smallAWordOnly).ALetters.Count); // --> 1
        smallAWordOnly.ALetters.Add(new LetterSmallA(2)); --> 2
        Console.WriteLine("d : " + smallAWordOnly.ALetters.Count);
        Console.WriteLine("b : " + ((WordwithALettersOnly)smallAWordOnly).ALetters.Count); // -> 1 
    }
}

Essentially derived classes are generated in the module 2 and processed in the external assembly module 1, on a/c reference loss.

Is the only way to translate the derived class objects of the module 2 to module 1 class objects

I hope i have been explain clearly the issue, if not i do apologise, would really appreciate solutions to this.

  • 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-25T02:05:53+00:00Added an answer on May 25, 2026 at 2:05 am

    If I understand your question correctly, what you want is to treat IList<LetterSmallA> as IList<LetterA>. This is not possible in C# and for very good reasons: one of the things IList<LetterA> says is possible to do with is is to “try to add any LetterA to it. This is not possible with IList<LetterSmallA> and so there is no built-in way to do what you want.

    What you can do is to create your own implementation of IList<T> that wraps another IList<T> of derived type:

    class BaseTypeList<TBase, TDerived> : IList<TBase>
        where TBase : class
        where TDerived : class, TBase 
    {
        private readonly IList<TDerived> m_derivedList;
    
        public BaseTypeList(IList<TDerived> derivedList)
        {
            m_derivedList = derivedList;
        }
    
        public IEnumerator<TBase> GetEnumerator()
        {
            return m_derivedList.Cast<TBase>().GetEnumerator();
        }
    
        public void Add(TBase item)
        {
            var derivedItem = item as TDerived;
            if (derivedItem == null)
                throw new ArgumentException();
            m_derivedList.Add(derivedItem);
        }
    
        public void Clear()
        {
            m_derivedList.Clear();
        }
    
        // other members implemented in a similar fashion
    }
    

    (The class constraints are not necessary, but make some code simpler.)

    Your setter for ALetters could then look like this:

    _aLetters = value;
    if(_aLetters == null)
        base.ALetters = null;
    else
        base.ALetters = new BaseTypeList<LetterA, LetterSmallA>(value);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my class design I ran into the following problem: class MyData { int
I have the following design: I have an Abstract class Instance , I have
Originally I had a design problem where I needed five subclasses of a superclass,
This is a Ruby design problem. How can I make a reusable flat file
I am thinking about a DB Design Problem. For example, I am designing this
I keep running into this design problem, and I'm not happy with my solution
I have some sort of a design problem with my Django AJAX application. I
Background : An art teacher once gave me a design problem to draw a
Here's my proposed (very simplified to illustrate the problem space) design for a C#
Is it a deliberate design decision or a problem with our current day browsers

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.