FOUNDATIONS OF PROGRAMMING : CODES AND OBJECTS : 05.03 PROCEDURAL AND OBJECT-ORIENTED PROGRAMMING

Terms in this set (5)

Most things you encounter daily are objects. Cars, furniture, even your phone. For each object, you can customize the way it looks, its different features, and what it can do. We define objects by their different attributes and behaviors.

These real-life objects can be simulated with program code. Take a look the following image to learn about some important terminology related to object-oriented programming.


Class: This refers to a template used to create new objects. Think of it as a blueprint that has existing characteristics you can use when creating new, but similar objects. Each time a new contact is added to your phone, it uses the contact class.

Instance: Many instances of a class can be created. For example, an object is an instance of a class. One individual contact in your phone is an instance of a contact object.

Constructor: This refers to the code that allows you to create a new object. It is a special method used when a new instance of a class is created. The initial values of the attributes are set. This is like adding (or constructing) new contacts in your phone.

Attributes: This refers to the features of an object. The attributes of a contact might include a phone number, email address, or picture. Attributes are often nouns and adjectives that define the properties or characteristics of the object.

Initializing: This refers to what the constructor will do when you use it to create a new object. It will initialize the object in the program. When you create a new contact, all of the attributes will have initial values.

Behaviors: Also known as methods, this refers to the actions an object performs. You can set specific ringtones or vibration patterns to a specific contact so that when that person calls, that specific behavior is performed.
REUSABLE CODE
Once programmers write a useful class for one programming project, they can often reuse that class in another program instead of starting from scratch. Example: If you create a class for a deck of cards, you can reuse it for any program needing a deck of cards, like Solitaire or Go Fish.

INHERITED TRAITS
Programmers can create new objects that inherit traits from existing classes. This means they can add new features to an object without having to recreate it from scratch, saving tons of time and effort. Example: If you create a vehicle class that has all the basic functionality of a vehicle (e.g. moves, carries people or things, starts and stops), you could build on that class to create more specific types of vehicles, like convertibles, bicycles or a semi-truck.

FLEXIBILITY
Programs created using OOP are easier to develop because of their flexibility. Objects can be used in a variety of ways and have different behaviors for different purposes, depending on the program. Example: If you create a class for your bank account, many bits of information (e.g. name, social security number, birthdate) are needed to open an account or get a loan. But for simple transactions like making a deposit, only basic information like your name and account number are needed. Your bank account class can work for all of these.

EASY TO MAINTAIN
Object-oriented programs are written modularly (in objects), making them easier to maintain and understand once developed. Example: If you're planning a meal and you burn the cupcakes, you only have to fix the cupcakes, not the whole meal. In OOP, objects can be maintained separately, making finding and fixing problems much easier.
;