Difference between internal and external messages

External messages are any messages sent to objects other than self. External messages are a dependency because the object needs to know the name of a message that other object will respond to.

class Comment
  attr_reader :body, :post
  def initalize(body, post)
    @body = body
    @post = post

  def capitalize_body

  def post_title

post = Post.new(title: "hi may name is someone")
comment = Comment.new(body: "this is a cool post", post: post)
# example of a message sent to self

The Comment#capitalize_body method sends a message to self. The Comment#post_title message sends the title message to the post object and depends on the post object to be able to respond to the title message. External message dependencies often cannot be avoided, but are still real dependencies that should be monitored and occasionally isolated into separate methods.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s