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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:10:22+00:00 2026-06-10T21:10:22+00:00

I’ve done some searching (maybe I’m not describing my problem well enough) but haven’t

  • 0

I’ve done some searching (maybe I’m not describing my problem well enough) but haven’t been able to find an answer for this

Let’s say you have the following POCO:

public class StandardObject
{
   public string A {get;set;}
   public string B {get;set;}
}

Somewhere else in the program there is some logic to handle StandardObjects.
There exists a case where sometimes a StandardObject may need to be handled differently. We know this when we create the StandardObject however none of the current properties can be used to determine this further down the chain. One approach would be to add and set a flag or type enum on StandardObject and check this when handling the objects. E.G.

if(standardObject.IsSpecial){...}

if(standardObject.ObjectType == StandardObjectTypeEnum.Special){...}

This doesn’t seem like the best approach though.

The other option would be to create a derived class:

public class SpecialObject : StandardObject { }

So now rather than checking a property, we can check the type. E.G.

if(standardObject.GetType() == typeof(SpecialObject)){...}

(Depending on what we were doing, the type checking might be implemented differently)

Note that SpecialObject does not add to or change StandardObject in any way. It is essentially the same object. This approach has the advantage of being more flexible (E.G. We could add some additional properties to SpecialObject) but in reality it won’t change. It will always be identical.

To me inheritance seems like the better approach. Type flags seem like code smell and going forward inheritance seems more like the correct OOP approach. The thing I’m not sure about here is that, given that StandardObject and SpecialObject are the same, is it bad practice to do this? Or are there any reasons why this should be avoided?

There is a similar question here:

Chess piece hierarchy design: inheritance vs type fields

However most of the discussion seems to focus on the chess problem rather than what is considered good design

EDIT:

Encapsulation seems to be the popular solution. The reason why I’ve avoided encapsulation is best described in the example below:

  • StandardObject is essentially a DTO
  • There is a list of StandardObject.
  • The list gets processed, StandardObject gets serialized
  • The serialized data is sent somewhere over any number of different protocols
  • One of the protocols requires certain parameters to be set if StandardObject is “special”

Given that the additional logic for “special” cases is only required by one of a number of different mechanisms that process StandardObject, the logic for this does not seem like it belongs anywhere near StandardObject

  • 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-10T21:10:24+00:00Added an answer on June 10, 2026 at 9:10 pm

    They are both code smells. If you have special handling that must be accomplished differently between two related types, have them both implement some virtual method or interface operation that allows them to handle the special case (or not, if it’s not necessary).

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

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms

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.