Designing classes and a grievance

This is a discussion on Designing classes and a grievance within the C++ Programming forums, part of the General Programming Boards category; First the grievance, why on earth did they switch the order when using a typedef versus a pound define? #define ...

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    25

    Designing classes and a grievance

    First the grievance, why on earth did they switch the order when using a typedef versus a pound define?

    #define <newname> <what it equals>
    typedef <what it equals> <newname>

    I understand the difference between preprocessor commands and new variable declarations and all that, but what bothers me is the order. At least they could have kept them similar!

    On to the actual question about classes and designing..

    How do you go about deciding what will make a good base class, and what would make a good derived class(es)? Also, how should you incorporate other libraries into classes to form good classes?

    I am having a hard time creating good classes. I am using a graphics/multimedia library. This is my first project using a large library and furthermore my first project using classes. I am not new to programming and I am well read, but designing a large (ish) project is pretty tough!

    Any tips on creating classes/incorporating other libraries/classes into your own?

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,658
    >> First the grievance, why on earth did they switch the order when using a typedef versus a pound define?

    "What bothers you is the order" Is it as bothersome when there is a purposeful use of typedef such as

    typedef char *(*functionPtr)(const char *, size_t, char *, size_t);

    Not all types are convenient keywords; in fact in C++ it's often a tangled, templated mess and it is more about remembering where to stick your alias. At worst, it's simply not convenient either way.

    At least with #define you could say that the most complicated part of it comes last.

    >> How do you go about deciding what will make a good base class, and what would make a good derived class(es)? Also, how should you incorporate other libraries into classes to form good classes?

    Uh, wow, how long is a piece of string?

    I do know that library classes make poor base classes unless they are explicitly documented as such. That's about as useful as I can be without going on a tangent. Is this related to what you want to know?
    Last edited by whiteflags; 12-02-2010 at 09:21 PM.

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    25
    I was curious about libraries as a base class. I don't think the library I am using would make a very good base class but I could be wrong.

    I am also curious about implementing my own bases and derived classes but using libraries within the methods. I guess it works fine but doesn't feel right. Wouldn't it cause unneeded overhead with constructors/deconstructors etc? I feel like it's adding another layer on the cake.

    I am new to OOP so I am quite curious ~_~

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    If the library doesn't have a virtual destructor, it shouldn't be used as a base class.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  5. #5
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,658
    >> I feel like it's adding another layer on the cake.

    There's a word for that: boilerplate. I couldn't tell you if it is without making my own opinion on your software first and then you would have to agree with my reasoning. There is no problem at all with using a library in a class though; it happens all the time. I imagine you've used std::string or std::vector by now in a class. Just because it's not standard doesn't mean using it in a class is automatically a bad idea. You just have to be familiar enough with the library to use it appropriately.

  6. #6
    Registered User
    Join Date
    Dec 2010
    Posts
    25
    Boilerplate, I learned a new word. Thanks!

    I think I can wing it out and complete the program and then have some very helpful people help critique my techniques and help me organize my program better. I think I can learn a lot that way.

    I can't help but feel like I am gluing the program together and wrapping it up with tape and praying it works out. Is this a natural feeling? I just wish there was an easier way to learn.



    semi off topic: I enjoyed this reading about the complexities of OOP/C++:
    The Duct Tape Programmer - Joel on Software

  7. #7
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,658
    For me it often does feel like I'm hacking parts together. It hasn't affected me.

  8. #8
    Registered User
    Join Date
    Dec 2010
    Posts
    25
    Good to know I am not the only one. Thanks!

Popular pages Recent additions subscribe to a feed

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21