I am facing dilemma on how to best design the following functionality. What design patterns and OOD principles should I use.

For simplicity sake following are basic requirements:

  • displays type can be any of the following: PC Monitor, LG TV, Samsung TV, or other manufacturer
  • displays can have different functionalities, for example: turn on, turn off, sleep, etc..
  • there should be available some metadata about displays, like
    • is CEC link available and working
    • is RS232 link available and working
    • is HDMI cable connected
    • is display currently turned on or off
    • get/set display resolution, etc...
  • communication with displays can be done in any of the following ways
    • RS232 serial cable commands (which are specific to manufacturer)
    • HDMI CEC commands
    • as a fallback (and for the monitors) we use EnergyStar features aka. xset dpms force off

I'm more familiar with the php, but I will probably implement this in python as it is more systems language and I suppose also more appropriate for this task.

In the end it could be something simple as following I suppose. It could manually figure out which link it has available for communication(cec|rs232) and which command it should send along that link depending on manufacturer of the display.

$display = new Display();
if ($display->isConnected() && $display->isOn()) {
$forfun = $display->getVendorName();

I was thinking about implementing something along this lines, but I can already some some problems with this:

/** DisplayFactory classes */
abstract class AbstractDisplayFactory {
    abstract function makeDisplay();

class LGDisplayFactory extends AbstractDisplayFactory {
    private $context = "LG";
    function makeDisplay() {
        return new LGDisplay;

class SamsungDisplayFactory extends AbstractDisplayFactory {
    private $context = "Samsung";
    function makeDisplay() {
        return new SamsungDisplay;

/** Display classes */
abstract class AbstractDisplay {

    abstract function turnOn();}
    abstract function turnOff();

    function hasCecLink() {
        //return status;
    function hasSerialLink() {
        //return status;
    function isHDMICableConnected() {
        // return status;

    // ....

class LGDisplay extends AbstractDisplay {

    function turnOff() {
        if($this->hasCecLink()) {
            // turn off via HDMI CEC - vendor agnostic commands
            // implementation of this would be better placed in a more generic class since
            // is vendor agnostic command, and we would not need to repeat it for every display
        else if($this->hasSerialLink()) {
            // turn off via rs232 - vendor specific commands
        else {
            // shell_exec('xset dpms force off')
            // this also would be better placed in a more generic class

    // ...

class SamsungDisplay extends AbstractDisplay {
    // similar as for LGDisplay class

I would be very happy of any pointers I could get about how to best approach this.


What would I like to achieve is to have a single entry point for display management and monitoring which would allow me to control different kinds of displays via different kinds of methods some of which are common to all displays while others are vendor specific methods.

This is embedded pc for signage displays therefore user is not local to the display.

It does not need to indicate capabilities back to the end-user, but it should indicate some capabilities back to the administrator.

The system should definitely pick preferred or best method when a control operation is requested and fall back to one which is always available and working for all displays if other better methods don't have prerequisites to get executed (like disconnected serial cable).

Some of the operations/requirements of the system I identified are:

  • system should be capable to turn display on and off via rs232 serial connection, if not available then via hdmi CEC, if not available then as a fall back execute command xset dpms force off
  • system should get information of the display such as:
    • is display on or off
    • is display connected to the PC
    • what is current resolution and its orientation
    • get list of supported resolutions
  • system should be able to set some display parameters such as:
    • set resolution, orientation and offset/position of the picture
    • set brightness

Some display parameters are going to be set/get directly via vendor specific methods(serial connection), while others in a vendor agnostic and more standardized path via hdmi CEC protocol, while others like resolution via operating system(with help of tools like xrand and others).

I suppose for this I should employ more than one design pattern, but I'm struggling which ones and how should I apply them to have such a plugable system so that the systems is extensible and that I don't to have deal with gazillion of if statements if I want to turn off tv for one or another kind of display via one or another method.

  • You presented more of an overview of the hardware than requirements. Can you identify all the operations the system needs to be capable of? Who's doing what when why? Does it need to indicate capabilities back to the end user? Is the user local to the display? Does it need to pick the best method to do a thing? Does it need to fall back if a thing fails? – Martin K Feb 11 at 20:51
  • Please clarify what problems you have. It seems more or less OK, although different approaches are possible. – ADS Feb 12 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.