In object-oriented programming, creating objects containing both data and functionality is the focus. The definition of OOP is that it is a model for writing computer programs, modeled around the interactions between objects. It involves writing classes that generate objects and define their structure. Object-oriented programming involves working with ADTs, or abstract data types.
For example, you can define a class Point, and give it the attributes x and y, as mentioned previously. Now that the class is defined, objects of this type Point can be created. When this class was created, a type of this class was also created. Point objects can also be called instances of type Point.
class Point:
"""
"""
def __init__(self, x, y):
""" (Point, int, int) -> NoneType
"""
self.x = x
self.y = y
Objects of this instance can be generated like this:
>>> p = Point(3, 4)
>>> p.x # p.x and p.y just accesses the values for this instance
3
>>> p.y
4
You can even write methods in classes, which look like functions but are a part of objects. As mentioned before, a method for this class could be distance_from_origin. It can be called like this on an object:
>>> p.distance_from_origin()
This way, the object p has data in the form of x and y, and functionality in the form of the method, distance_from_origin. Another excellent, existing example of object-creating ADTs are stacks. Stack is a class and type, which has data and also functions in terms of push(), pop() and is_empty(). In conclusion, object-oriented programming involves creating objects through classes, with data in the form of attributes and functions in the form of methods.