Search Unity

Resolved What is your opinion on representing different types of objects by the same class?

Discussion in 'Visual Scripting' started by Marou1, Nov 28, 2022.

  1. Marou1

    Marou1

    Joined:
    Dec 13, 2021
    Posts:
    161
    Hi,

    I'd like to have your opinion:

    Let's say I have 3 types of buildings: Type A, Type B and Type C.
    Buildings have shared properties and specific properties:

    Would you represent each building by a class:

    Class A:
    SharedProperty1
    SharedProperty2
    SharedProperty3
    SpecificPropertyA1
    SpecificPropertyA2
    SpecificPropertyA3

    Class B:
    SharedProperty1
    SharedProperty2
    SharedProperty3
    SpecificPropertyB1
    SpecificPropertyB2
    SpecificPropertyB3

    Class C:
    SharedProperty1
    SharedProperty2
    SharedProperty3
    SpecificPropertyC1
    SpecificPropertyC2
    SpecificPropertyC3

    Or use 1 class for all:

    Class Building:
    SharedProperty1
    SharedProperty2
    SharedProperty3
    SpecificPropertyA1
    SpecificPropertyA2
    SpecificPropertyA3
    SpecificPropertyB1
    SpecificPropertyB2
    SpecificPropertyB3
    SpecificPropertyC1
    SpecificPropertyC2
    SpecificPropertyC3

    Pros for 3 classes:
    Clean since there is not a bunch of unused properties
    Visually easier to work with in the inspector, specially if there are a lot of specific properties

    Cons for 3 classes:
    Maintenance of 3 different classes and multiplying the number of scripts that handle the shared properties for each specific class.

    Pros for 1 class:
    Maintenance of only 1 class and the same scripts that handle the shared properties for all the buildings. Much more efficient for future modifications.

    Cons for 1 class:
    A long class of dozens of properties, many of them not used for a specific type of building.
    Visually tedious to work with in the inspector.
    (Performance impact?)

    What's do you think?
     
  2. Trindenberg

    Trindenberg

    Joined:
    Dec 3, 2017
    Posts:
    398
    Marou1 likes this.
  3. Marou1

    Marou1

    Joined:
    Dec 13, 2021
    Posts:
    161
    Thank you so much!!!
    That's exactly what I need!
     
    Trindenberg likes this.