13.11. More on Methods

We've discussed methods in a fair amount of detail in this chapter and in Part One of this book. Now it's time to round out the discussion with a few more important observations about methods.

13.11.1. Message Chaining

In OOPLs such as C#, it's quite commonplace to form complex expressions by concatenating one method call onto another via dot notation, a mechanism known as message chaining. Here's one hypothetical example:

Student s = new Student();
s.Name = "Fred";

Professor p = new Professor();
p.Name = "John";

Course c = new Course();
c.Name = "Math";

s.setFacultyAdvisor(p);
p.setCourseTaught(c);

Course c2 = new Course();

// A message "chain".
						c2.Name = "Beginning " + (s.GetFacultyAdvisor().GetCourseTaught().Name); ...

Get Beginning C# 2008 Objects: From Concept to Code now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.