Re: Mixing OO and DB
Date: Tue, 19 Feb 2008 08:18:55 -0600
Message-ID: <2008021908185575249-unclebob_at_objectmentorcom>
On 2008-02-18 21:09:48 -0600, David BL <davidbl_at_iinet.net.au> said:
> I have a more specific understanding of LSP. Let an object mean a
> variable that has identity, state and behavior, but isn't assumed to
> hold a value. If S,T are object types where S is a subtype of T then
> LSP states that if q(x) is a property provable about objects x of type
> T. Then q(y) should be true for objects y of type S.
>
> In my mind LSP is inappropriate for value-types because it is
> concerned with variables rather than values.
Sorry to butt in but Liskov didn't make a distinction about value-types. The substitution principle simply says that every program P that works with T should also work with S.
It is easy to envison a T and S that are pure value types. Imagine,
for example, an Address type, and a subtype that supports 9 digit
zipcodes. Any program written for Addess can safely use the subtype.
BTW, while it is true that real numbers are a subtype of complex
numbers (i.e. any algorithm that works when the I part is non-zero
should work when the I part is zero), it is not true that Real inherits
from Complex.
-- Robert C. Martin (Uncle Bob) | email: unclebob_at_objectmentor.com Object Mentor Inc. | blog: www.butunclebob.com The Agile Transition Experts | web: www.objectmentor.com 800-338-6716 |Received on Tue Feb 19 2008 - 15:18:55 CET