3 Introduction To Objects and Classes
3 Introduction To Objects and Classes
This lesson introduces you to the concept of objects and classes and the bene ts of using them.
• A Brief Encounter
• Objects and Classes
• Properties
• Methods
• Bene ts of Objects and Classes
A Brief Encounter #
We can see objects everywhere in our surroundings. These objects have
certain properties that define them. There are certain behaviors that these
objects perform on their own, and there are actions that can be performed on
them as well.
Let’s take the example of a company employee. An employee has the following
properties or attributes:
ID
Salary
Department
In a company, each worker has a different name, salary, and department but
the type of each worker is employee. So, there is a generic blueprint for each
worker working in the company, but each one of them has different attributes
associated with them.
Having the same blueprint but different properties are the basis for classes
and objects.
ID: 72655
Salary: 3000
Department: Software
Mark
ID: 72644
Salary: 4000
Department: Marketing
Chris
Properties
ID
salary
department
Methods
tax()
salaryPerDay()
employee class
Properties #
Properties are variables that contain information regarding the object of a
class. An employee object will have an ID , a salary , and the department as its
properties. New properties could be added to be a part of an object of the
employee class.
Methods #
Methods are like functions that have access to properties (and other methods)
of a class. Methods can accept parameters and return values. They are used to
perform an action on an object of a class. In the example above, we have
tax() and salaryPerDay() as class methods.