Monday, July 13, 2015

C# Class Terminology

C# Class Terminology

Class

Class – template for an object. An object is an instance of a class.

Static Class - a class that cannot be instantiated. This type of class can be used when no internal fields are needed for the class methods to function.

Base Class – also known as the parent class. Base class is the class being "inherited”.

Derived Class – also known as the child class. Derived class "inherits” from another class.

Sealed Class – prevents the class from being "inherited”.

Abstract Class – a class that must be "inherited” to be used. An "Interface” is a completely abstract class. (Abstraction)

Enum Class – a class that contains constant (read-only) variables .

Fields and Properties

Fields – variables inside a class.

Property – used to "Encapsulate” fields. Properties are used to get and set the value of a field. They allow and control access to private fields. Properties allow fields to be "read-only” (get), "write-only” (set) , or "read-write” (get;set;).

Method

Method / Function – contain code / logic and perform actions.

Method Parameter – pass information to a method from another method or object. Used as variables inside the method. Parameters can have "default” values.

Method Return Values – return information to the calling method or object.

Constructor Method – method used to instantiate a new instance of the class. Typically used to set the initial value of fields. A class can have multiple constructors with different signatures (parameters).

Virtual Method – allows a "derived” class to "override” the functionality of the base class method. (Polymorphism).

Override Method – overrides the functionality of the base class method.

Abstract Method – a method that has no code and must have an override method in the derived (child) class. (Abstraction)

Access Modifiers

"Public” fields, methods, and properties can be accessed inside the class or by other objects.

"Private” fields, methods, and properties can be accessed inside the class only.

"Protected” fields, methods, and properties can be accessed inside the class or from a "Derived” class.

"Internal" fields, methods, and properties can only be access inside of the assemmbly.

Example Code: