Re: Is this good use of Properties?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"Rick Elbers" <rick.elbers@xxxxxxxxx> wrote in message
news:q9se81t04g7sjh288j4lf8m8viileus5lo@xxxxxxxxxx
> Jon,
>
> On Sun, 15 May 2005 07:58:17 +0100, Jon Skeet [C# MVP]
> <skeet@xxxxxxxxx> wrote:
>
>>Rick Elbers <rick.elbers@xxxxxxxxx> wrote:
>>> >Ah yes - I seem to remember seeing it before and disagreeing with it
>>> >then. The idea that a class should be able to draw itself just in case
>>> >it's needed in a UI seems ridiculous to me - which UI should be picked,
>>> >for instance? SWT? Swing? AWT? All three? What about a web UI? What
>>> >happened to separating presentation logic from business logic? How can
>>> >the author of a business class know all the different ways in which it
>>> >may need to be drawn?
>>>
>>> We agree! In this kind of cases I rather use bridge pattern which you
>>> only implement IF you need a specific OS/Framework. On the other hand
>>> if you have the choice to make a shape know how to connect to other
>>> shapes and draw itself on device context the shape itself has identity
>>> and is a valid class. If on the otherhand shape is only telling
>>> client-"managers" what it is, can do and how it draws in my view shape
>>> is a property bag which is not a valid class. My choice is to make it
>>> without the managers..:-)
>>
>>Well, that depends on whether it knows in advance what the managers
>>will want to do. Again I give the example of String - is that not a
>>proper class? It only knows about itself and what it consists of. It
>>allows manipulation (into new strings) and retrieval of the text.
>>That's all it needs to do.
>>
>>In other words, it concentrates on its domain (text) and nothing else.
>>That appeals to me.
>>
>
> Strange concept of domain do you display here. In my view domain is
> application domain. String has no application domain, its a framework
> class and as such very special. The string class is appealling ever
> since stl prototyped the first version thats sure, however its not my
> model for domain classes at all. Its an utility kind of class in my
> view. It might be that this is the reason for our miscommunication.
>
>
>
>>> >It puts the onus on a class to know all the ways in which it might be
>>> >used, rather than providing something which can be used in a variety of
>>> >situations.
>>>
>>> Interesting statement. Do you think we can formulate a basic tension
>>> in design: encapsulation versus usability ? Class for all users is on
>>> the one hand the absolute monolite, property bag for all users in on
>>> the other hand the absolute dumbo.
>>
>>No-one has suggested that all classes should expose everything about
>>their implementation as properties though. No-one's claimed that
>>properties are the universal solution - we've just claimed that they're
>>not the anti-pattern you see them as.
>>
>>I only expose things as properties when I see a need to, but I often
>>*do* see a need to expose *some* of the state of a class as a property.
>>That state isn't always a direct mapping with the variables of the
>>class, of course - it's the logical state of what the class logically
>>describes. As such, the state is part of the interface of the class
>>just as much as the methods are.
>>
>>> > I can see it working in some situations, but overall I'm
>>> >not a fan.
>>>
>>> If we talk the context of beginners it might be different from
>>> experienced programmers. Experienced programmers have made some smart
>>> objects, and know the value of encapsulation. Maybe they are on the
>>> risk of goldplating. Beginners on the other hand certainly those from
>>> procedural or database worlds might gain from the challenge to make
>>> smart objects since their risk might be to make goto spaghetti code
>>> with objects in property bags..
>>
>>So tell people not to expose every variable as a property - tell them
>>to be selective. I have no problem with that. When you tell them that
>>properties are anti-patterns with simple statements like "don't use
>>accessors" you're making far too strong a statement in my view.
>
> Ok. Strong statements sometimes work, sometimes they dont lol
>
> Regards and see u around,
>
> Rick
>

I still don't see your points Rick. Sorry. Asking a string object for its
length is no problem. It wouldn't be a method in that class if it were.

Accessors are good and allow you to valide incoming values to set on the
property. Properties allow more levels of encapsulation. I still don't see
any point for not using them. Although you believe universally they
shouldn't be part of OO. The large number of OO books published will
religiously disagree with you.

What I gather is Rick believes accessors are bad and stings shouldn't expose
length, of which I have seen him make no valid point for those reasons.

Jon, if you believe Rick has made any valid points, please rephrase them
into your own thoughts. I find his wording difficult to understand. It
would help me to see what exactly he is argueing against.

Any who, thanks.

Brett


.



Relevant Pages

  • Re: Formulas containing hard coded values
    ... Dim R As Range, sdoit As String ... MsgBox "Cell contains hard codes" ... ' Grateful thanks to Rick Rothstein ... Dim Fml As String, LCtext As String ...
    (microsoft.public.excel.programming)
  • Re: Converting ISBNs: 13 to 10
    ... Dim LastRow As Long ... Const ISBNcolumn As String = "A" ... Const ISBNoutColumn As String = "B" ... Rick ...
    (microsoft.public.excel.programming)
  • Re: How do i strip off Upper case Characters to another cell in Ex
    ... Here is the revised UDF without the Replace function... ... Function GetUpperLetters(ByVal strRange As String) As String ... Rick ... For intTemp = 1 To Len ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Using Domain User ID
    ... ' This code was originally written by Dev Ashish. ... Function fOSUserNameAs String ... Dim lngLen As Long, lngX As Long ... Rick B wrote:> I always recommend using real Access security. ...
    (microsoft.public.access.security)
  • Re: time format
    ... I knew I was on a good track with the string replacement method, but I was surprised how long it took me to get it right. ... Rick ... Private Sub Worksheet_Change ... >> Private Sub Worksheet_Change(ByVal Target As Range) ...
    (microsoft.public.excel.misc)