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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:33:22+00:00 2026-05-16T06:33:22+00:00

Base class is Task. There are several derived classes such as PhoneCall, Fax, Email….

  • 0

Base class is Task. There are several derived classes such as PhoneCall, Fax, Email….
The framework is .NET 3.5 and the language is C#

In our application, we want to create some automatic tasks based on certain rules for a customer. For eg. if the customer has been signed up for 30 days, a task will get created by the rules engine.

The owner of the task should then be able to convert this task into a PhoneCall, Fax….. based on the scenario. Also, another requirement will be to convert a PhoneCall to Fax or Email or vice versa.

1) Should there be a converted class that should facilitate this conversion or each business object should allow methods to perform conversion?

2) If there are any design patterns or guidance someone can provide, that will be great.

Pratik

  • 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-16T06:33:23+00:00Added an answer on May 16, 2026 at 6:33 am

    Inheritance is not necessarily the best way to model problems where instances of types can change over time.

    You may want to consider using composition instead. Something like:

    class Task
    {
        private TaskDetail m_Detail;
    
        public TaskDetail Detail { get { return m_Detail; } }
    }
    
    abstract class TaskDetail { ... }
    
    class PhoneCallDetail : TaskDetail { ... }
    class FaxDetail : TaskDetail { ... }
    class EmailDetail : TaskDetail { ... }
    

    Tasks would not change when their task details shift from one type to another. You would also need to implement some utility code to convert between the different task types, as appropriate.

    So example use might look like:

    Task theTask = new Task( ... );
    theTask.ConvertToEmail(); // internally establishes this as an email task
    
    EmailDetail detail = (EmailDetail)theTask.Detail;
    detail.EmailAddress = "wiley.coyote@acme.com";
    
    theTask.ConvertToFax();   // may transfer or lose some detail...
    FaxDetail faxDetail = (FaxDetail)theTask.Detail;
    faxDetail.FaxDate = DateTime.Now;
    
    // and so on.
    

    The primary disadvantage to the approach above is that consumers of the Task class must use runtime checks to determine the type of detail associated with the task before operating on it; which also then requires casting of the detail property everywhere:

    Task someTask = ...;
    if( someTask.Detail is EmailDetail )
    { 
        EmailDetail detail = (EmailDetail)someTask.Detail;
        /* operate on email detail ... */
    }
    else if( someTask.Detail is FaxDetail )
    {
        FaxDetail detail = (FaxDetail)someTask.Detail;
        /* operate on fax detail ... */
    }
    

    As the number of different subtypes grows, this approach becomes harder to maintain and evolve. If the number of subtypes is small, and likely to be stable over time, then it may be a reasonable choice.

    In general, it’s difficult to model situations like these – and you often have to compromise based on what persistence provider you use, how many different detail types they are, and what use cases you intend to support involving conversions from one detail type to another.

    Another design approach that is often employed in such cases is Key-Value-Coding. This approch uses a dictionary of keys/values to model the various data elements of different kinds of details. This allows details to be very flexible, at the cost of less compile-time safety. I try to avoid this approach when possible, but sometimes it does model certain problem domains better.

    It’s actually possible to combine key-value coding with a more strongly typed approach. This allows details to expose their properties (usually for read-only purposes) without requiring the caller to perform runtime checks or casts:

    abstract class TaskDetail
    {
        public abstract object this[string key] { get; }
    }
    
    public class FaxDetail : TaskDetail
    {
        public string FaxNumber { get; set; }
        public DateTime DateSent  { get; set; }
    
        public override object this[string key]
        {
            get
            {
                switch( key )
                {
                    case "FaxNumber": return FaxNumber;
                    case "DateSent":  return DateSent;
                    default:          return null;
                }
            }
        }
    }
    
    public class EmailDetail : TaskDetail
    {
        public string EmailAddress { get; set; }
        public DateTime DateSent { get; set; }
    
        public override object this[string key]
        {
           get
           {
               switch( key )
               {
                   case "EmailAddress": return EmailAddress;
                   case "DateSent":     return DateSent;
                   default:             return null;
               } 
           }
        }
    }
    
    // now we can operate against TaskDetails using a KVC approach:
    Task someTask;
    object dateSent = someTask.Detail["DateSent"]; // both fax/email have a DateSent
    if( dateSent != null )
       // ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.