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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:45:58+00:00 2026-05-18T03:45:58+00:00

I have a situation where I have 2 Activity objects (let’s say empty and

  • 0

I have a situation where I have 2 Activity objects (let’s say empty and scheduled activity, not controlled by me) that share a couple of behaviors, like the person who booked the activity, the room where that activity takes place, activity type, subject etc.

I created two wrappers objects (EmptyWrapper and ScheduledWrapper) that have a super class ActivityWrapper that implements some methods common to both childs and has some abstract methods/properties for the child wrappers to respond accordingly. They are very much alike in behavior but there is one crucial difference, you can only schedule activities if it is an empty slot! The structure is something like this (very simplified code):

 public class EmptyWrapper : AppWrapper
 {
    EmptySlot _emptySlot;        

    public EmptySlotWrapper(EmptySlot emptySlot) : base()
    {
        this._emptySlot = emptySlot;
    }

    public override string Id
    {
        get { return _emptySlot.AgendaId; }
    }

    public override string Room;
    {
        get{ return _emptySlot.Room;}
    }

    public override string Person
    {
        get{ return _emptySlot.Person;}
    }

    public override string AppType;
    {
        get{ return "Empty";}
    }

    public override bool IsAppSlot()
    {
        return false;
    }

    public override bool IsEmptySlot()
    {
        return true;
    }

    public override bool CanPerformOperations()
    {
        return true;
    }

    public void ReserveApp(ObjWithActivityInfo actObj)
    {
        (...)            
    }
 }

The ActivityWrapper is similar but the object wrapped around is different, the bools return true for IsAppSlot, false for IsEmptySlot and false for CanPerformOperations and there is no ReserveApp() method.

Next is the base class:

public abstract class AppWrapper
{
    public abstract string Collaborator { get; }
    public abstract string Room { get; }
    public abstract string AppType { get;}

    public AppWrapper()
    { }

    public abstract bool IsAppSlot();
    public abstract bool IsEmptySlot();

    public abstract bool CanPerformOperations();

    public virtual string GetTextToShow()
    {
        return Person + " - " + Room;
    }

    (...)
}

In my code I wanted to reference only the ActivityWrapper, because for the general operations (show the info and appearance) I don’t need the implementations. The problem rises when I need to book activities for empty slots. In that point, in my code, I cast the AppointmentWrapper to the EmptyWrapper and reserve the slot for the activity (it is still an EmptySlot but it’s reserved to the selected activity), otherwise, if the cast was unsucessful I don’t do anything because it was not the correct Activity Type.

Is this correct, or should I implement the ReserveActivity() method in both wrappers and have the ActivityWrapper do nothing?

Or should I do this in another way? Maybe to alter the structure of the classes?

Sorry for the long text.

  • 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-18T03:45:58+00:00Added an answer on May 18, 2026 at 3:45 am

    There is no point in adding a function to a class that does not require it. It would defeat the point of your inheritance.

    I’d do a safe cast …

    var i = obj as theClass
    

    and then test for null. I’d use a bit of linq to select all o the objects that have the property you defined to indicate what type they are set to true.

    You could do it the other way and save yourself the cast and test, but it means the design is less obvious to an outsider.

    I think its a matter of taste but prefer the way you did it. I am not sure i like the bool properties to identify the type though. What if you inherit off the base class again? Besides you can cast to identify the type – which with a deeper object structure may be more useful.

    I agree with your desire to work with a collection of the abstract class though.

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

Sidebar

Related Questions

No related questions found

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.