OOP - Class Design

Discussion in 'Programming' started by jeisma, Dec 1, 2012.

  1. jeisma

    jeisma Junior Member

    Joined:
    Dec 1, 2012
    Messages:
    1
    Likes Received:
    0
    Hi!

    I'm in very early stages of OOP. Coming from a procedural programming, I'm starting to see the change in mindset when designing my application.

    My first project:

    Convert numbers, date, time values in different languages. Language is not known until run time.

    This is how I designed my classes.

    Interface ILang. With methods num_to_words(), date_to_words(), time_to_words().

    And above interface implemented by these classes: French. English. Spanish. German...

    I'm not comfortable about this design. Maybe I should have a class Number, or Date, or Time?

    How would you design your classes? Which pattern works best with this scenario?


    Thank you!
     
  2. douglasb

    douglasb Diamond Member

    Joined:
    Apr 11, 2005
    Messages:
    3,163
    Likes Received:
    0
    Presumably, the "number", "date", "time", etc. would use the classes that are built in to most languages (Integer, for example). Or they would just be primitive types. At any rate, you are over-complicating it. You have a generic ILanguage and however many classes that implement it. For what you are trying to do, you really don't need to abstract it any further than that.
     
  3. douglasb

    douglasb Diamond Member

    Joined:
    Apr 11, 2005
    Messages:
    3,163
    Likes Received:
    0
    What programming language?
     
  4. beginner99

    beginner99 Platinum Member

    Joined:
    Jun 2, 2009
    Messages:
    2,810
    Likes Received:
    2
    Dates, times, timezone etc are extremely problematic and not easy at all. Save your time it has been done and I very strongly suggest using a standard library for that problem regardless of language.
     
  5. clamum

    clamum Lifer

    Joined:
    Feb 13, 2003
    Messages:
    23,636
    Likes Received:
    3
    For your project, I'd say what you have is decent. No need to over-think it like douglasb metioned.

    How about trying a simple game, like maybe Blackjack? Or check beginner C# of Java books/tutorials for ideas on simple apps to get the hang of OOP.
     
  6. eyahaloms

    eyahaloms Junior Member

    Joined:
    Dec 16, 2012
    Messages:
    10
    Likes Received:
    0
    I think its a good design. And I've been using C++ object oriented for 12 years.
    Basically the client gets a ILang pointer (in Run time), which is basically a derived class
    and does the conversion.