Re: OO Concepts and C# Properties

From: Phlip (phlip_cpp_at_yahoo.com)
Date: 02/03/04


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


Relevant Pages

  • Re: Variable uses a type not supported in Visual Basic (Error 458)
    ... > Microsoft Visual Basic for Applications Software Development Kit ... > interface in a Visual Basic class, ... > generate libraries that use a Visual Basic- or Visual Basic for ... > Rebuild your type library by pressing CTRL+F7 or selecting Compile ...
    (microsoft.public.vb.bugs)
  • Re: Recommendations for JavaScript drop-down menu code
    ... to not having a long enough history working with browsers to ... Obviously these individuals are not aware that there code has these issues following from their inexperience, but now your project manager cannot solve his problem by just using a library unless he has someone who knows the issues themselves and so can point out which libraries properly handle them and which doe not. ... interface and a base implementation of that interface. ... but it is still important that the interface design stage takes into account the need to accommodate the whole range of possible implementations of the interface. ...
    (comp.lang.javascript)
  • Re: iChat, one mans meat ...
    ... IM clients? ... I'd argue that iChat is a better user interface *for their target ... the chat colouring idea predates iChat by quite a long way. ...
    (uk.comp.sys.mac)
  • Re: TrueCrypt 4.0 Out
    ... >> Again you show that you know very little about information security. ... > If you don't understand the code enough to change a calling interface ... reasons for not making changes to this code unless this cannot be avoided. ... I can certainly now see why you mistkenly think that libraries are ...
    (sci.crypt)
  • Re: Recommendations for JavaScript drop-down menu code
    ... rare browsers may not be considered a wise ... for all the standard Java libraries, ... interface and a base implementation of that interface. ... implementations that are employed in the context, ...
    (comp.lang.javascript)