jeudi 26 juillet 2018

Looking for feedback on a new printer design, (pseudocode) C++

I'm currently creating a new design for a printer service and I wanted feedback on how you guys think the current design is. This will be coded in C++03

I've tried to adhere to SOLID principles by giving every class/interface one responsibility and separating all functionality into separate interfaces.

The functionality which this printer will have (so far) is as follows:

  • Print Logos
  • Print Lines (horizontal)
  • Print Barcodes (1D or 2D (QR codes))
  • Print Text (Left, Center, Right Aligned), this text will also be formatted with a Font
  • Then there is a Printer class which holds the functions the outside world will call.

so yeah feedback is welcome (Below is the class design in pseudocode)

interface ILogo
{
    void PrintLogo();
}

class WatermarkLogo inherits ILogo
{
    void PrintLogo();
}

-----------------------------------------------------

interface ILine
{
    void PrintLine();
}

class PlainLine inherits ILine
{
    void PrintLine();
}

class DottedLine inherits ILine
{
    void PrintLine();
}

-----------------------------------------------------

interface IBarcode
{
    void PrintBarcode();
}

class OneDimensionalBarcode inherits IBarcode
{
    void PrintBarcode();
}

class TwoDimensional inherits IBarcode
{
    void PrintBarcode();
}

------------------------------------------------------

interface IText
{
    Font m_font;
    void PrintText();
}

class TextLeftAligned inherits IText
{
    void PrintText();
}

class TextCenterAligned inherits IText
{
    void PrintText();
}

class TextRightAligned inherits IText
{
    void PrintText();
}

class TextLeftRightAligned inherits IText
{
    void PrintText();
}

-----------------------------------------------------
enum FontStyleType
{
    Normal = 1,
    Bold = 2,
    Italic = 3,
    Underlined = 4
}

class FontStyle
{
    FontStyleType GetFontStyle();
}

enum FontFamilyType
{
    Arial = 1,
    Calibri = 2,
    TimesNewRoman = 3
}

class FontFamily
{
    FontFamilyType GetFontFamily();
}

class Font
{
    unsigned int m_size;
    FontFamily m_fontFamily;

    unsigned int GetFontSize();
    FontFamily GetFontFamily();
}

-----------------------------------------------------

class Printer
{
    IBarcode m_barcode;
    ILine m_line;
    IText m_text;

    void SetBarcodeType(const IBarcode& barcode);
    void SetLineType(const ILine& line);
    void SetTextAlignment(const IText& text);

    void PrintBarcode(const std::string& barcodeToPrint);
    void PrintLine();
    void PrintText(const std::string& textToPrint);
}

Aucun commentaire:

Enregistrer un commentaire