procedure oriented programming is based on the defining of functions which each has a job to do, and the functions together form the basis of the program, you can use python for 'pop' by only using function definitions, object-oriented programming is where
you can organize specific functions that are similar or work together into a class like a noun (object) which has certain actions/verbs it can perform (functions/methods). The class can not only hold specific functions/methods but also hold its own attributes(data
members/variables with values) which are supposedly only visible to its inner parts (its functions/methods) which is termed data encapsulation in OOP programming, what makes OOP programming so useful is that its classes are isolated from other classes and
only interact through function/method calls making modification of the program easy by not having to go and change everything in all of the methods to make it compatible with your updates, say you make two classes, one for computing trig. functions and another
for computing inv. functions, if you were to make an error in one of them and you know the other one works just fine then your changes are isolated to only the class that needs the fix, kinda like taking out a broken module from the system and fixing it then
plugging it back in without touching any other parts of system
object are instantiated(a unique copy is created in memory) as needed by the user and each time they are instantiated their constructors are called, these constructors initialize any of the object's own variables before they are used by any methods, to initialize the object's variables before they're used is good OOP practice since it prevents the dependence of the programmer on the user to know how to initialize the variables before they're used thus preventing possible errors
here some Java code for OOP:
public class SomeClass
{
int var1;
String string1;
// no parameter constructor
public SomeClass()
{
var1 = 12345;
string1 = "Let assign this string before any methods use this variable";
}
public int getVar1()
{
return var1;
}
public String getString1()
{
return string1;
}
}
and the equivalent in python:
class SomeClass:
"""documentation string (optional)"""
def __init__( self ):
self.var1 = 12345
self.string1 = "Lets assign this string before any method uses it"
def getVar1( self ):
return self.var1
def getString1( self ):
return self.string1
# end of class declaration
all methods including constructors must specify at least one parameter, that one parameter is the object reference which allow the methods of the class to access its own variable and other methods of its own. By convention this parameter/argument is named 'self', it isn't specific when you call the object ( class = SomeClass(), class.getVar1(), class.getString1() ) but when you define the class you have to specify it
object are instantiated(a unique copy is created in memory) as needed by the user and each time they are instantiated their constructors are called, these constructors initialize any of the object's own variables before they are used by any methods, to initialize the object's variables before they're used is good OOP practice since it prevents the dependence of the programmer on the user to know how to initialize the variables before they're used thus preventing possible errors
here some Java code for OOP:
public class SomeClass
{
int var1;
String string1;
// no parameter constructor
public SomeClass()
{
var1 = 12345;
string1 = "Let assign this string before any methods use this variable";
}
public int getVar1()
{
return var1;
}
public String getString1()
{
return string1;
}
}
and the equivalent in python:
class SomeClass:
"""documentation string (optional)"""
def __init__( self ):
self.var1 = 12345
self.string1 = "Lets assign this string before any method uses it"
def getVar1( self ):
return self.var1
def getString1( self ):
return self.string1
# end of class declaration
all methods including constructors must specify at least one parameter, that one parameter is the object reference which allow the methods of the class to access its own variable and other methods of its own. By convention this parameter/argument is named 'self', it isn't specific when you call the object ( class = SomeClass(), class.getVar1(), class.getString1() ) but when you define the class you have to specify it