language agnostic - What is the preferred way to store different versions of data? -


What if you are writing an application that requires reading and working with two versions of data The best way to organize my classes to represent that figure is to come up with three scenarios:

  1. General support / special children
  2. data union
  3. Different Textures

Version 1 Car Example

  Byte Dwarkat is Int Color byte Byte Bite HasSpoiler Float Engine Segment Byte CylinderCount  

Version 2 Car

  Byte Dorcant Ent Color Enum: Int Mouneroff Type Anonym: Int Trunk Assets: Engine Engine Type  Normal basis / specific children   

The method with it, between two versions of data and one child class for each version of the data The common areas are the base class.

  class car {byte dwarcount; Int color; } Class carrier 1: car {byte smootherroof; Byte Hespiiler; Float Engines; Byte cylinders; } Class Performance 2: Car {Ent Moonrof Type; Int TrunkAccessories; Int engine   
  • Existing child class
  • Data for a conceptual unit is divided between two definitions, because it does not make sense for any partitions.

    Data Union

    Here, a car is defined as a union of car fields in all versions of data.

      class car {career edition; Byte Dwarkount; Int color; Type monoraph type; // Boolean if version 1 int trunk accessories; // Boolean type version 1 engine; // CylinderCount if version 1 engine floats engine; // if not use version 2}  

    strength

    • Um ... everything is in one place.

    Vulnerabilities

    • Forced case driven code.
    • Difficult to maintain when another version is released or heritage is removed.
    • Concepts are difficult

    Specific Structures

    The structures have no OP relationship with each other here. However, the interface can be implemented by both classes if / when code expects them to be in the same fashion.

      class Carverions1 {byte Dwarcount; Int color; Byte Hasamonoff; Byte Hespiiler; Float Engines; Byte cylinders; } Class CarVersion2 {Byte Dwarcount; Int color; Type monoraph type; Int TrunkAccessories; Int engine  

    strength

    • Simple approach
    • New version added or legacy has been removed, so easy to maintain.

    Vulnerabilities

    • This is an anti-pattern.

    Is there a better way about which I did not think? It is obvious that I favor the last methodology, but is it better to do first?

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

If two versions of data structure are used in the normal application / module - then they must apply the same interface period. Certainly unable to write two separate application modules to handle two different versions of the data structure. The fact is that the underlying data model is very different, it should be irrelevant. After all, the goal of writing objects is to achieve the practical level of incompression.

As you keep writing codes in this way, you should eventually find out where the code is same or unnecessary in the two sections. If you move the code of these common pieces from different version sections, you can eventually end up with the version sections, which not only apply the same interface, but also implement the same base / abstract class You can. Voice, you've discovered your own way on your "first" option.

I think it is the best way in an environment with constantly evolving data. For this, some diligence and old code need "seek back", but the code is worth the benefit of clarity and reusable components.

Another thought: in your example, the base class is "car". In my opinion, it has hardly ever been known that the base class is so "close" that its successor has another realistic set of base class or interface, perhaps "version", "upgradeable", "option container", etc. Could. Just talking to my experience, YMMV


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -