Object Oriented Programming Concepts - C#

Object-oriented Programming Concepts

An object-oriented program is a collection of objects sending messages to one another. The following table lists several terms with which you should be familiar.

Term Description
Classes Classes are the basic unit of any object-oriented language.

  • Classes are the templates used to create objects.
  • Classes can be used to define new data types.
  • All programming must be done inside of a class.
  • Classes contain member variables and member methods.
Object An object is an instance of a class.

  • Instances are created by declaring a variable of the class type to hold a reference to an instance (or object) of that class.
  • Instantiate or create a new instance of a class using the new keyword.
Method The behavior of the program is defined inside the body of methods.

  • All methods must be in a class.
  • Methods consist of a header and zero or more statements
Fields The fields of a class are the data members (variables) that are used to track the state of the class.

  • Data members are variables declared inside of the class.
  • Data members can be variables of any type.
  • Data members usually cannot be directly accessed outside of the class.
  • Properties provide a nice way of indirectly accessing data members outside of a class.
Properties In a generic sense, a property is any data member or field associated with an object. Properties are unique to a class instance. In a way, it is the object's properties that differentiate one object from another. In a strict sense, object properties are better referred to as fields or data members.

In a formal sense, a property is a programming construct that lets you access (get) or modify (set) the fields of an object.

Event An event is a class member that enables an object or class to provide notifications. You can write event handlers that link code to events. When the event occurs, the code in the linked handlers is executed.
Namespace Namespaces are used to organize the program and prevent name collisions.

  • Namespaces contain classes, a variety of other programming constructs, or other namespaces.
  • The System namespace ultimately contains all of the namespaces and classes in the .NET libraries.