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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:50:57+00:00 2026-05-13T12:50:57+00:00

When you’re writing an application that needs to read and work with two versions

  • 0

When you’re writing an application that needs to read and work with two versions of data in the same way, what is the best way to structure your classes to represent that data. I have come up with three scenarios:

  1. Common Base/Specific Children
  2. Data Union
  3. Distinct Structures

Version 1 Car Example

byte DoorCount
int Color
byte HasMoonroof
byte HasSpoiler
float EngineSize
byte CylinderCount

Version 2 Car

byte DoorCount
int Color
enum:int MoonRoofType
enum:int TrunkAccessories
enum:int EngineType

Common Base/Specific Children

With this method, there is a base class of common fields between the two versions of data and a child class for each version of the data.

class Car {
    byte DoorCount;
    int Color;
}

class CarVersion1 : Car {
    byte HasMoonroof;
    byte HasSpoiler;
    float EngineSize;
    byte CylinderCount;
}

class CarVersion2 : Car {
    int MoonRoofType;
    int TrunkAccessories;
    int EngineType;
}

Strengths

  • OOP Paradigm

Weaknesses

  • Existing child classes will have to change if a new version is released that removes a common field
  • Data for one conceptual unit is split between two definitions not because of any division meaningful to itself.

Data Union

Here, a Car is defined as the union of the fields of Car across all versions of the data.

class Car {
    CarVersion version;
    byte DoorCount;
    int Color;
    int MoonRoofType;     //boolean if Version 1
    int TrunkAccessories; //boolean if Version 1
    int EngineType;       //CylinderCount if Version 1
    float EngineSize;     //Not used if Version2
}

Strengths

  • Um… Everything is in one place.

Weaknesses

  • Forced case driven code.
  • Difficult to maintain when another version is release or legacy is removed.
  • Difficult to conceptualize. The meanings of the fields changed based on the version.

Distinct Structures

Here the structures have no OOP relationship to each other. However, interfaces may be implemented by both classes if/when the code expects to treat them in the same fashion.

class CarVersion1 {
    byte DoorCount;
    int Color;
    byte HasMoonroof;
    byte HasSpoiler;
    float EngineSize;
    byte CylinderCount;
}

class CarVersion2 {
    byte DoorCount;
    int Color;
    int MoonRoofType;
    int TrunkAccessories;
    int EngineType;
}

Strengths

  • Straightforward approach
  • Easy to maintain if a new version is added or legacy is removed.

Weaknesses

  • It’s an anti-pattern.

Is there a better way that I didn’t think of? It’s probably obvious that I favor the last methodology, but is the first one better?

  • 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-13T12:50:57+00:00Added an answer on May 13, 2026 at 12:50 pm

    Why is the third option, distinct structures for each version, a bad idea or anti-pattern?

    If the two versions of data structures are used in a common application/module – they will have to implement the same interface. Period. It is definitely untenable to write two different application modules to handle two different versions of data structure. The fact that the underlying data model is extremely different should be irrelevant. After all, the goal of writing objects is to achieve a practical level of encapsulation.

    As you continue writing code in this way, you should eventually find places where the code in both classes are similar or redundant. If you move these common pieces of code out of the various version classes, you may eventually end up with version classes that not only implement the same interface, but can also implement the same base/abstract class. Voila, you’ve found your way to your “first” option.

    I think this is the best path in an environment with constantly evolving data. It requires some diligence and “looking behind” on older code, but worth the benefits of code clarity and reusable components.

    Another thought: in your example, the base class is “Car”. In my opinion, it hardly ever turns out that the base class is so “near” to it’s inheritors. A more realistic set of base classes or interfaces might be “Versionable”, “Upgradeable”, “OptionContainer”, etc. Just speaking from my experience, YMMV.

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

Sidebar

Ask A Question

Stats

  • Questions 339k
  • Answers 339k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'm not sure that I understand your question; what you've… May 14, 2026 at 4:33 am
  • Editorial Team
    Editorial Team added an answer By the sound of it, what you're looking to create… May 14, 2026 at 4:33 am
  • Editorial Team
    Editorial Team added an answer $date1 = new DateTime(); $date2 = new DateTime(); $date2->add(new DateInterval('P3Y'));… May 14, 2026 at 4:33 am

Related Questions

In order to apply a triggered animation to all ToolTip s in my app,
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
When you execute a SQL query, you have to clean your strings or users
When you are starting a personal programming project, what is your first step? I'm
When you are doing integration tests with either just your data access layer or

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.