Ticker

6/recent/ticker-posts

OOPS (Object Oriented Programming Language) Part-1

 Object oriented Programming Language  (OOPS-1)

Introduction to OOPS

Object -oriented programming language (OOPS) is a programming paradigm based on the concept of "objects" and "classes' that contain data and methods. The primary purpose of OOP is to increase the flexibility and maintainability of programs. It is used to structure a software program into simple, reusable pieces of code blueprints (called classes) which are used to create individual instance of objects.

   Python supports a variety of programming approaches. One of the most useful and popular programming approaches is OOPS. 

What is an object ?

The object is an entity that has a state and behavior associated with it. It may be any real-world object like the mouse, keyword, chair, table, pen, etc.

Integers, strings floating -point numbers, even arrays and dictionaries, are all objects. more specifically ,any single integer or any single string is an object. The Number 12 is an object. The String "Hello World" is an object, a list is an object that can hold other objects, and so on. You have been using objects all along and may not even realize it.

What is a Class?

A Class is a blueprint that defines the variables and methods (Characteristics) common to all objects of  a certain kind.

Example : If Car  is a class, then Maruti 800 is an object of the Car class. All cars share similar features like 4 wheels, 1 Steering wheel, window, breaks etc. Maruti 800 (The Car object) has all these features.

Classes vs Objects (or Instances)

Classes are used to create user-defined data structures. Classes defines functions called methods, which identify the behaviors and actions that an objects created from the class can perform with its data.

In this module, you will create a Car class that stores some information about the characteristics and behaviors that an individual Car can have.

A class is a blueprint for how something should be defined. It does not contain any data. The Car class specifies that a name and a top-speed are necessary for defining a Car, but it does not contain the name or top-speed of any specific Car.

while the class is the blueprint, an instances is an object that is built from a class and contains real data. An instance of the Car  class is not a blueprint anymore. it is an actual car with a name,  like Creta, and with a top speed of 2000 km/hr.

Put another way, a class is like a form or questionnaire. an instance is lake a form that has been filled out with information. Just like many people can fill out the same form with their unique information, many instances can be created from a single class.

Defining a Class in Python



Post a Comment

0 Comments