OOP - Class Design

jeisma

Junior Member
Dec 1, 2012
5
0
61
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!
 

douglasb

Diamond Member
Apr 11, 2005
3,163
0
76
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.
 

beginner99

Diamond Member
Jun 2, 2009
5,210
1,580
136
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.
 

clamum

Lifer
Feb 13, 2003
26,255
403
126
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.