Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Action and query methods  RSS feed

 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
after reading this post i went to check this app i'm building and now i'm confused...

basically i'v this class (called Convencao) that has several members such as id, name and also has a contact (called Contacto) - which i designed as a diferent class.

i rushed to my code and got this from a test: (pessoa == person)


am i using querymethods? (and so doing it the wrong way, because someone from outside can alter the state of contacto state without giving notice to container class Convencao)

should i instead shape Convencao with a public interface with methods like:
public void setContactName(String name)?

TiA
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you're in a good place here. We talk about relationships like Convencao hiding information about its Contacto and you're doing that fine. The part we might have skipped talking about is how they learn about each other. It's ok for some other object to glue them together. Make sure that assembling the two things fits well with the knowlege and responsibilities of the assembler.
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[ May 02, 2005: Message edited by: miguel lisboa ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing you posted that to show the dark path . Now you're not telling Convencao anything new, you're getting some of its internals and messing about with them, a dangerous direction.
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stan James:
I'm guessing you posted that to show the dark path . Now you're not telling Convencao anything new, you're getting some of its internals and messing about with them, a dangerous direction.

my intention wasnt that, but instead show how i think things should be done: imagine someone wants to update contact's name: instead of accessing class contact directly, calls Convencao to do it; then convencao acts with the above method.
Is that so wrong?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's interesting to have a design goal of no get() methods. (You'll likely wind up with a few anyhow, but trying to avoid them is usually a Good Thing.) To remove the getContacto() method, we might add a new set method:

myConvencao.setContactName( name );

Oh! That's just what you said and I missed it! With the fragment you posted INSIDE convencao, it's cool.

See if these tales of The Really Rather Good Idea of Demeter help, too.
[ May 02, 2005: Message edited by: Stan James ]
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why get/set are evil article was very cool because it opened the OO door to me: that was first time i heard about CRC's
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!