dimanche 10 juillet 2022

How would I structure a class for a universal remote that sends an On/Off command to various devices connected to it?

I want to create a universal remote class where multiple devices are connected to it. I know they wont extend from the remote but unsure how I would send a power off /on command to all of them.

I was thinking like:

const tv = new TV()
tv.isOn // gives false
const light = new Light()
light.isOn // gives false
const xbox = new Xbox()
xbox.isOn // gives false
const remote = new Remote()
remote.on()
tv.isOn // gives true
light.isOn // gives true
xbox.isOn // gives true

So now if you check like the TV object to see if it was on it would be or the lights etc.

In my head

class TV extends Remote

sounds dumb. but I cant think of a way where just calling the remote class would change all the other objects. I'm fairly new to coding so any help would be appreciated

Aucun commentaire:

Enregistrer un commentaire