views:

882

answers:

3

Steve Yegge describes the Properties Pattern in a blog post of his.

For someone using a static language like C# or Java, what are the advantages and disadvantages of this approach? In what kind of projects would you want to use the Properties Pattern, and when would you want to avoid it?

+1  A: 

The properties pattern is especially useful (or, it has been for me), when your want to make prototypes of objects or have a development structure that somewhat forces you to have an iterative deployment of your API/Interfaces.

If you start out with an idea of some properties of an object, then you make them. Later on you find (and you have anticipated this finding...) that your understanding of the subject area was not adequate, you make a new object design/behavior based on the prototype of the first object. And so forth. The wiki-page on the subject has a very good description of the subject in conjunction with static typed languages, but I would recommend that you looked into JavaScript or Lua if you're really serious with prototyping development. The properties of prototypes are not mutable in the static typed languages, and this fact will eventually bite you down the road.

Edit: Oh, and I see you link to an excellent post on the subject. Yegges use/explanation of the subject of course does dwarf my own. Please read it through a couple of times and the advantages/implications of the use of the properties pattern in a language like java should be very clear to you.

Edit.2: link to wikipedia article: http://en.wikipedia.org/wiki/Prototype_pattern

Steen
Thanks for the great response! I didn't find a wiki article... link?
Greg
The wikipedia entry might be what is referred to - http://en.wikipedia.org/wiki/Prototype-based_programming. (Within three minutes google manages to reference this question. heh. I wonder if I can break google with some kind of recursion here ...)
le dorfier
The link to http://en.wikipedia.org/wiki/Prototype-based_programming seems more like what I and Steve Yegge are referring to.
Greg
Yes, Yegge refers to prototyping as a technique, but the basis for prototyping in this respect is the properties pattern and or the prototype pattern. Which to use or blend is a matter of implementation and restrictions in the language of choice
Steen
A: 

Personally what I find to be the greatest benefit to me is it makes it clear to me (as someone who's using another programmer's class) what I'm allowed to access and change. It's not so clear when you just use public fields.

Ray Hidayat
Perhaps you are thinking of the Properties, the C# feature?
Greg
A: 

For someone using Java, as I read the article, I'd say you can't use the Properties Pattern on any projects, because quote:

Java offers essentially zero support for the Properties Pattern.

Same would be true for C# for the same reasons. I felt a little comforted when I came to that statement, because I sure wasn't finding any way to fit them together.

So I'm not sure I understand your question. But thanks for the link - upvote the question for that alone. Now I understand some things I halfway intuited a little better.

le dorfier
I agree that C# and Java can't fully embrace the Properties Pattern. However, using an indexer, dictionary, and hierarchy, one can mimic many of the features of the Properties Pattern. I'm wondering when that might be useful...
Greg
Writing jQuery might be one example. Another is those role-playing games where you accumulate weapons and tools. And for civilization games where there are lots of objects of varying cumulative character.
le dorfier
But I'll take your word for it that it can be faked in java; I can't envision it, my mind immediately phase-shifts into javascript mode.
le dorfier
I'll just be presumptuous enough to challenge the view held by Yegge. His example refers to a system (his game Wyvern) that is entirely based on the pattern. In this case you could forward the view that java (or any static typed language) void support. But If you design for change, it's usable.
Steen