V
V
vilix2016-12-15 14:47:33
OOP
vilix, 2016-12-15 14:47:33

What is the best way to design classes in this example?

There are devices controllers - Controllers, they have the same set of attributes. But they can be of different manufacturers and depending on the manufacturers different features and functions.
So far I have a Controller class :

  • ID
  • Name
  • address
  • DeviceId - by this ID it will be possible to get the technical characteristics of this type of device, for example, the manufacturer.

I plan to store this class through orm in the Controllers table.
Next, I want to put functions for working with controllers, they should be grouped by manufacturer.
In my head, I create a class on the manufacturer that inherits the Controller. For example :
ControllerVendor1 : Controller
  • setData()

ControllerVendor2 : Controller
  • setData()

Although the names of the functions are the same, the code will be different.
Next, I need, when getting from the database, to get the controller of the desired type. To do this, I think in the Controller.get () method - check, by the deviceId of the manufacturer and, depending on it, create the desired controller and return it. return new ControllerVendor1(controller)
To what extent is this a normal decision, and what is the best way to do it?
C# language;
in Device displays the capabilities of the device model.
device:
  • ID
  • ModelName
  • Vendor
  • workmodes

Real life example: Let's say we have two manufacturers of controllers Vendor1 and Vendor2, we bought 2 pieces of the first and 1 piece of the second, named them ctr1, ctr2, ctr3.
Then
Devices: { {id: 1, vendor: "Vendor1"},  {id: 2, vendor: "Vendor2"} }
Controllers { {id: 1, name: "ctr1", deviceId: 1}, { id: 2, name: "ctr2", deviceId: 1}, { id:3, name: "ctr3", deviceId: 2} }

PS Device I'm going to store not in the database, but somewhere it will be sewn up in the code.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alexchin, 2017-01-25
@alexchin

Everything seems to be ok. There are suspicions?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question