Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Programming Style  RSS feed

 
leo donahue
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a term for this style of writing code?

Note: SomeObjects2, 3 and 4 are Interfaces.

 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you could call it "violently violating the Law of Demeter"...
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote up a longish response then deleted it so I can ask: Describe the style. What part of what I'm seeing here is important? What do you think might be good or bad about it?
 
leo donahue
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stan James:
What part of what I'm seeing here is important? What do you think might be good or bad about it?


Well, I'm not sure. I see alot of examples like this in a third party java API. It seems like I can compare it to swing in the sense that I can get a JButton without going through class Object, then Component, Container, etc. But with this third party java API, it seems to me that in order to get somewhere, I have to chain everything together. Is this normal?
 
leo donahue
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start on page 8.

Example of what I'm seeing
[ August 23, 2006: Message edited by: leo donahue ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, if the focus is on the chains of gets to get anything done, I'm with Ilja. The design winds up with a code snippet knowing too much about too many other classes. Here's some light-hearted stuff I pulled from various sources on Demeter.

I'm trying to think of a condition that would make this "not too bad." Maybe if the other classes are VERY stable, ie they won't change in the next 10 releases. To the good, they made a lot of those things interfaces so they may have appropriately made the most stable things also the most abstract.

It's not really possible or ideal to follow the rules of Demeter all the time. Exceptions like this are something we live with now and then. Again, using interfaces is rather encouraging.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!