Re: Is this good use of Properties?

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



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

.



Relevant Pages

  • Re: Is this good use of Properties?
    ... The idea that a class should be able to draw itself just in case ... > is a property bag which is not a valid class. ... No-one has suggested that all classes should expose everything about ... not the anti-pattern you see them as. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Lets Build a Roguelike (Draft)
    ... Why do you have the row: Draw String, m, ... 'Iterate through the menu array and draw items to the screen. ... cname As String * 40 'Name of character. ... Enum attrib ...
    (rec.games.roguelike.development)
  • Re: Is this good use of Properties?
    ... >>> is a property bag which is not a valid class. ... String has no application domain, ... >>No-one has suggested that all classes should expose everything about ... I still don't see your points Rick. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Medieval English long bows
    ... draw the string back with the string arm). ... away with the bow arm, while twisting the body, permits much more power. ... A two finger grip will commonly fail well below 100 lbs, ...
    (soc.history.medieval)
  • Re: To display a picture
    ... The image is in TIFF format, ... ENM> GDI is very fast. ... Is your picture owner-drawn and how do you draw? ... // Create a string. ...
    (microsoft.public.vc.atl)