Python For Og Lecture 79 and 80 - Oop Part 5 Encapsulation Abstraction and Name Mangling
Python For Og Lecture 79 and 80 - Oop Part 5 Encapsulation Abstraction and Name Mangling
Website - https://petroleumfromscratchin.wordpress.com/
LinkedIn - https://www.linkedin.com/company/petroleum-from-scratch
YouTube - https://www.youtube.com/channel/UC_lT10npISN5V32HDLAklsw
# ENCAPSULATION
# It just means all the data and all methods to be used with data are at one place
class Scores:
def __init__(self, res_score, drill_score, prod_score):
# instance variables
self.score_reservoir = res_score
Saved successfully!
self.score_drilling = drill_score
self.score_production = prod_score
/
def avg(self):
2/3/2021 Python for O&G Lecture 79 and 80: OOP - Part 5 - Encapsulation, Abstraction and Name Mangling - Colaboratory
def avg(self):
return {(self.score_reservoir + self.score_drilling + self.score_production)/3}
def maximum(self):
return max(self.score_reservoir, self.score_drilling, self.score_production)
# this is an example of encapsulation only. All the required things are at a single place. Encapsulated
# Abstraction
por.append(0.25)
print(por)
# in many programming languages for example java and c++ there are some private methods and variables and some are public
# but sometimes we give our code to someone else. We want them to not change certain things
# we can use _name instead of name to let them know that this is private to me, please don't change it
Saved successfully!
class Well:
mw = 11.2
def __init__(self, compl_type, zones, depth):
self.type_of_completion = compl_type
self.num_of_zones = zones
self.depth_of_well = depth
def press_calc(self):
return 0.052*Well.mw*self.depth_of_well
well_a.type_of_completion
'open'
class Well2:
mw = 11.2
def __init__(self, compl_type, zones, depth):
self._type_of_completion = compl_type # just to indicate please treat this as a private property
self.num_of_zones = zones
self.depth_of_well = depth
def press_calc(self):
return 0.052*Well.mw*self.depth_of_well
well_b._type_of_completion
Saved successfully!
/
2/3/2021 Python for O&G Lecture 79 and 80: OOP - Part 5 - Encapsulation, Abstraction and Name Mangling - Colaboratory
'open'
class Well3:
mw = 12.1
def __init__(self, compl_type, zones, depth):
self.__type_of_completion = compl_type
self.num_of_zones = zones
self.depth_of_well = depth
def press_calc(self):
return 0.052*Well3.mw*self.depth_of_well
well_d.__type_of_completion
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-13-1c335acee91e> in <module>()
14 well_d = Well3('slotted liner', 4, 3900)
15
---> 16 well_d.__type_of_completion
well_d.__dict__
Saved successfully!
/
2/3/2021 Python for O&G Lecture 79 and 80: OOP - Part 5 - Encapsulation, Abstraction and Name Mangling - Colaboratory
# why python does this?, so that this variable remains associated with this class only.
# we'll understand this in INHERITENCE
Saved successfully!