Right or Wrong Way To Do This?

From: Carl Revell (no.spam_at_no.spam.com)
Date: 10/16/03


Date: Thu, 16 Oct 2003 10:49:45 +0100

I have a simple business object representing a manufactured item. It has an
identifying member variable from which I need to provide currently two
different representations but maybe more at a later date.

For example.

- m_ProductId: 1234ABC999

+ GetId() returns 1234ABC
+ GetId() returns 999

Later, GetId() might need to return 1234DDMMYYYY (where DDMMYYYY are day,
month and year)

Is it best to create a single public method GetId() say, which accepts
several parameters (maybe from an enumerated list) like this...

Enum IdType (idt7Digit, idt3Digit, idt4PlusDate)

And then call GetId(idt7Digit) or GetId(idt4PlusDate) and so on to return
the required formatted Id?

OR

Create different methods for each type of formatted Id, thus

Get7DigitId()
Get3DigitId()
Get4PlusDateId()

I figure separate methods would be required if the return type was different
for some returned Id formats, but assuming a string-type is always returned
is one way better than another or is there a third, preferred option?

Thanks,

Carl