Chapter 3: Methods


Overview

Methods are fundamental both to C# class design and also to the MSIL code emitted by the C# compiler. This chapter explores both of these areas and explains how to design and code effective methods in your classes.

Methods represent actions associated with a class. A method is a sequence of statements that encapsulate a discrete task or process. At run time, the inner working of your method is hidden from the client code, and the client code will invoke methods in the class without any knowledge of the actual working of the method. In object oriented programming terms, this is known as encapsulation. In essence, methods represent the behavior of your class.

Methods should be named to describe the task that they perform. Choosing the name of the method is an important consideration of the class design process as the method name forms part of the semantic contract between the class designer and the class-consuming client code. As C# is a case-sensitive language, it is possible to create two methods that only differ by the case of the name of the method. This should be avoided as it causes ambiguity.




C# Class Design Handbook(c) Coding Effective Classes
C# Class Design Handbook: Coding Effective Classes
ISBN: 1590592573
EAN: 2147483647
Year: N/A
Pages: 90

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net