Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 867e4a9

Browse files
Minor tweaks and updation
1 parent a32aa9c commit 867e4a9

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

‎OOP/Encapsulation/Data Abstraction.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
class Person:
2-
def __init__(self, first, last, id, email):
2+
def __init__(self, first, last, mob_num, email):
33
self.firstName = first
44
self.lastName = last
5-
self.id = id
5+
self.id = mob_num
66
self.email = email
77
self.friends = []
8+
# if access == "customer":
9+
# self.previ = "customer"
10+
# elif access == "staff":
11+
# self.previ = "admin"
12+
813

914
def add_friend(self, friend):
1015
if len(self.friends) < 10 and len(friend.friends) < 10:
11-
self.friends.append(friend)
12-
friend.friends.append(self)
16+
self.friends.append(friend) # p1 is addimg p2 in his friends list
17+
friend.friends.append(self) # p2 is adding p1 in his friends list
18+
19+
def getCustomerList(self):
20+
'''
21+
@name : getCustomerList
22+
@param1 : NA
23+
@desc : this is previleged method, only consumable to staff/admin
24+
@return : None
25+
'''
26+
#since we do not store information in DB, admin previleged guys cannot able to retrieve data which stands in iterpreter.
27+
pass
1328

1429
def getFriends(self):
1530
print (len(self.friends))
@@ -19,8 +34,18 @@ def getFriends(self):
1934

2035
p1 = Person("David", "Wolber", "922-43-9873", "wolber@usfca.edu")
2136
p2 = Person("Bob", "Jones", "902-38-9973", "jones@usfca.edu")
37+
p3 = Person("admin", "admin", "123", "admin.gmail.com")
38+
39+
print(p1)
40+
41+
print(p2)
42+
2243
p1.add_friend(p2)
2344

45+
46+
2447
print (p1.firstName)
2548
print (list(p1.friends))
49+
print(p1.friends[0].firstName)
50+
2651
print (p1.getFriends())

‎OOP/Encapsulation/DataHiding.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
# Example : A capsule tablet contains many types of chemicals, therefore it's called as a Capsule.
33

44
class SampleClass(object):
5+
6+
# below two global variables are nothing but a class attributes.
57
globalNumVariable = 3691
68
globalStringVariable = "Some string.."
79

810
b = 987 # b is a global variable
911
_b = 654 # can be called as protected
1012
__b = 321 # private
1113

12-
# constrcutor.
14+
# prameterized constrcutor, why do we call as parameterized constructor?
1315
def __init__(self):
14-
self.a = 123 # OK to access directly
16+
self.a = 123 # OK to access directly only by object.
1517
self._a = 456 # should be considered protected
1618
self.__a = 789 # considered private, name mangled , more secure Data
1719

@@ -27,9 +29,10 @@ def _getProtectedData(self):
2729
# Below method (which is inside the class) is considered as Private method(used double underscore
2830
# before the method name.
2931
def __getMoreSecureDataMethod(self):
30-
print(self.__a)
32+
print(self.__a)#directlt printing self.__a private member variable.
3133

3234
if __name__ == '__main__':
35+
3336
# Lets first try to create an object of SampleClass.
3437
objOfSampleClass = SampleClass() # object will get created here.
3538
m = SampleClass() # creating another object for the same class (reason : n number of obj can be created for a class)
@@ -39,7 +42,7 @@ def __getMoreSecureDataMethod(self):
3942
print(objOfSampleClass._b)
4043
# If you want to bring private value/variable outside the class, normally its not possible.
4144
# Below is going to throw an error (uncomment and execute it)
42-
print(objOfSampleClass.__b)
45+
# print(objOfSampleClass.__b)
4346

4447
# But if you do still, want to bring the value outside the class. then follow the below line of code.
4548
# using objOfSampleClass, lets call two global variables

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /