Object oriented programming in C#
Learn C# (C sharp) in FREE step-by-step lessons.
Object oriented programming in C#
You have been using classes and objects throughout this course.
In this lesson, you will create your own class.
Important Terms
- Accessors: Accessors retrieve values from the class, usually named get___, also called getter functions
- Attributes: Variables that are defined in a class are called attibutes or properties.
- Class: code that specifies the attributes *variables) and member functions (methods)
- Constructor: Method with same name as class, used to give initial values to the attributes.
- Data hiding: making attributes (variables) private and controlling access to them with methods (functions)
- Destructor: Member function with same name as the class with a ~ in front. The destructor is called when the object is destroyed.
- Encapsulation: combining data and code into a single object
- Instance: An object created from the class. (Using a constructor)
- Members: Objects can have their own data, including variables and constants, and their own methods. The variables, constants, and methods associated with an object are collectively refered to as its members or features.
- Mutators: Mutators change the values in the class, usually named set___, also called setter functions.
- Object: combines data(attributes, properties, variables) and member functions(methods).
- Overloaded constructors: Constructors can be written with different parameters. Usually there is one constructor with no arguments (the default constructor) and ones with different attributes given values.
- Overriding:Writing a method such as ToString() that already exists for a class by default.
- Private: (access specifier) Private attributes and methods can only be used inside the class definition.
- Public: (access specifier) Public attributes and methods are ones that can be accessed outside the class definition.
In order to do this you will:
- Understand the advantages of object oriented programming (classes);
- Be able to create and use a class;
- Be able to use a built in class such as the Date;
- Be able to create a class using inheritance.
Please study the material at each of the links below.
- Fraction Class with variables and constructors
/csharp/videos/csharp-fraction.mp4
- Fraction Class with Accessors, Mutators, and <
/csharp/videos/csharp-fraction2.mp4
- Working with the DateTime class.
- A Person Class.
- An Employee Class derived from the Person Class (Inheritance).