Re: OO Concepts and C# Properties
From: Phlip (phlip_cpp_at_yahoo.com)
Date: 02/03/04
- Next message: Graham Perkins: "Re: Structure design/programming"
- Previous message: H. S. Lahman: "Re: Class Diagrams as Requirements or Design?"
- In reply to: Daniel Parker: "Re: OO Concepts and C# Properties"
- Next in thread: Uncle Bob (Robert C. Martin): "Re: OO Concepts and C# Properties"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 03 Feb 2004 00:24:41 GMT
Daniel Parker wrote:
> And yet it's a fully encapsulated abstract data type. It hides the
> calculation of the leap year, which is a non-trivial calculation that many
> (including library vendors) have gotten wrong. It's internal
representation
> is completely transparent to the user.
>
> Would you prefer a date class with methods like format, rollForward,
> rollBackward, addTo, etc? Perhaps one that supported more than the
> Gregorian calendar, and dropped the methods that were particular to that
> calendar?
Shouldn't the object clients of the class vote on its interface? If they
know the month, they assign the month. If they know the offset in days, they
roll forward. Per the "intentional programming" principle, the interface
should be the intersection of the client objects' needs. But without them,
guesses about an interface's "OO quality" are less than useful.
The example of a "Date" class could mislead, because we see them most in
generic published libraries where the remote clients are assumed to have a
wide range of needs, and the interface averages all of them. For example,
suppose we treat the C library mktime() system as your "object". You can
roll forward by adding any number to the "mday" field of an otherwise
healthy tm structure, then passing this structure thru mktime(). It will
perform the mechanics of normalizing the date, and re-assigning the year,
month and mday based on how far out of the current month mday went.
This object interface satisfies your "roll forward" requirement, but behind
a facade of (conceptual) gets and sets for days and months. But in an
application-specific Date class, if nobody needs roll-forward, don't provide
it. And if nobody needs gets or sets, don't provide them either. Provide the
interface that permits clients to write intention-revealing statements.
--
Phlip
http://www.xpsd.org/cgi-bin/wiki?TestFirstUserInterfaces
- Next message: Graham Perkins: "Re: Structure design/programming"
- Previous message: H. S. Lahman: "Re: Class Diagrams as Requirements or Design?"
- In reply to: Daniel Parker: "Re: OO Concepts and C# Properties"
- Next in thread: Uncle Bob (Robert C. Martin): "Re: OO Concepts and C# Properties"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|