SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Two separate classes or one ?

    Hi,
    this is C++ and not PHP but I think you OOP guy will help me about my issue.

    I'm developing a C++ class that will write to a graphic-LCD-controller (a small 320x240 pixel display that could be BW or 256colors).

    Basically now I'm using this:

    Code:
    class dev_Lcd  {
    public:
    	enum Mode {BLACKWHITE, COLORS};
    	enum Orientation {PORTRAIT, LANDSCAPE};
    private:
    	Mode        d_mode;
    	Orientation d_orientation;
    public:
    	// CREATORS
    	dev_Lcd(Mode mode, Orientation orientation);
    	~dev_Lcd();
    	// MANIPULATORS
    	void refresh(const char *screen);
    };
    the refresh method is different based on the mode and based on the orientation.
    So in pratice the refresh has a ``switch'' based on d_mode and d_orientation.

    I was thinking to use another method, though.

    Code:
    // BASE CLASS for common things
    class dev_Lcd  {
    public:
    	// CREATORS
    	dev_Lcd();
    	~dev_Lcd();
    	// MANIPULATORS
    	virtual void refresh(const char *screen);
    };
    
    class dev_LcdBwPortrait  : public dev_Lcd {
    public:
    	// CREATORS
    	dev_LcdBwPortrait();
    	~dev_LcdBwPortrait();
    	// MANIPULATORS
    	void refresh(const char *screen);
    };
    
    class dev_LcdBwLandscape  : public dev_Lcd {
    public:
    	// CREATORS
    	dev_LcdBwLandscape  ();
    	~dev_LcdBwLandscape  ();
    	// MANIPULATORS
    	void refresh(const char *screen);
    };
    
    // same for color mode
    what would you use ?
    Approach 1) or 2) ?


    Criticisms are welcomed...thanks
    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03

  2. #2
    SitePoint Member
    Join Date
    May 2004
    Location
    Denmark
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I would go for the 2 classes approach.

    Imh this would represent a more scalable solution. Let's say you wan't to ad another orientation. If you use 2 classes adding a third class wouldn't affect the behavoiur af the existing classes. This way you will minimize your testing expenses

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2003
    Location
    hamburg, germany
    Posts
    103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    dito

    definitely 2-class-approach

  4. #4
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    Quote Originally Posted by pippo
    Basically now I'm using this: ... what would you use ?
    Approach 1) or 2) ?
    Approach 2 or Aproach 3 . Can you promote the orientation to a class? That way you can have two different orientation objects passed in and when the Ldc wants to calculate something that is orientation dependent it just asks the orientaton object. It also means you could pass a different orientation later and so change it at run time (if this is possible in the hardware).

    This now means 6 classes...
    Code:
    class Display { ... }
    class ColourDisplay : public Display { ... }
    class BlackAndWhiteDisplay : public Display { ... }
    class Orientation { ... }
    class Portrait : public Orientation { ... }
    class Landscape : public Orientation { ... }
    You can use the same trick for the colour modes (ColourDriver), but this strikes me as overkill at the level you are working on and is not a decision of the application anyway. Just have the detection object create the appropriate display.

    BTW, why the underscore concatentated and abreviated names? Are you using an EC++ compiler? Standard C++ has namespaces now - just put everything into an "Lcd" namespace.

    Ah...fond memories...

    yours, Marcus
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  5. #5
    SitePoint Guru
    Join Date
    Oct 2001
    Posts
    656
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Always use as many classes as possible Never go for the one-class-fits-it-all approach when you can have 20 or 30 classes

    (Ok, that may be a bit of an overstatement, but you get my point

  6. #6
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks you for all your precious suggestions,
    I'll think about them and I'll post what I'm going to use.

    > BTW, why the underscore concatentated and
    > abreviated names? Are you using an EC++ compiler?
    > Standard C++ has namespaces now - just put
    > everything into an "Lcd" namespace.
    I used C++ only in 1994 and for few time too, didn't know namespace exists at all!
    Thanks for that.

    I'm using the gcc compiler for the h8300 microncontroller, in particular I'm using these set of gnutools.
    So namespaces are available .
    I don't have too much RAM/ROM problems, the speed is a problem (MPU running at 16mhz!) so I always have a look at perfomance!


    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •