0

Here is the Problem Statement.

The Scenario is that I have many Platforms, and each of the platform has certain unique identities, lets consider it as graphic_cards, hardware, software and interfaces.

  1. Each of the Platforms can run a specific set of commands that is compatible with the given platform.

  2. Example:

    • Platform 1: Zodiac: GC1, HW1, SW1, INT1
    • ....
    • Platform n: Star: GCn, HWn, SWn, int n

I need to write a code in such a way that the script analyses which platform it is and runs the commands specific to only that Platform.

So far I have tried this,

class Platform(object):
a = None
B = None
C = None
D = None

def __init__(self, A,B, C, D):
    self.A = A
    self.B = B
    self.C = C
    self.D = D

class ZODIAC(Platform):

A = attr.A_map_dict

def __init__(self, A, B, C, D):
    super(ZODIAC, self).__init__(A, B, C, D)
perror
  • 7,071
  • 16
  • 58
  • 85
  • 1
    Please be more specific, at this point, your question is rather hard to understand. – Reblochon Masque Aug 13 '18 at 04:19
  • Don't create class variables `a = None`, `B = None`, etc., `self.A` will create an instance variable, see https://stackoverflow.com/questions/2714573/instance-variables-vs-class-variables-in-python – AChampion Aug 13 '18 at 04:19

1 Answers1

0

I would make a set of subclasses, and then a completely separate method to analyze your parameters and generate the class you want:

class Platform(object):
    a = None
    b = None
    ...
    def __init__(self, A, B, C, D):
        ...
    ...
    def execute_commands():
         # abstract method - platform-specific, defined by subclasses

class ZODIAC(Platform):
    A = attr.A_map_dict
    ...
    @override
    def execute_commands():
        # platform-specific behavior, overriding superclass

def generate_platform(a, b, c, d):
    if a == 'onething' and b == 'anotherthing':
        return ZODIAC(a, b, c, d)
    elif c == 'somethingelse':
        return OTHER_PLATFORM(a, b, c, d)
    ...

Write generate_platform() in such a way that it determines which platform is correct from the variables given. It will then return an instance of the appropriate subclass of Platform. This is an illustration of the principle of polymorphism, one of the pillars of object-oriented programming.

Green Cloak Guy
  • 23,793
  • 4
  • 33
  • 53