Skip to content

Instantly share code, notes, and snippets.

View kcsanjeeb's full-sized avatar
🎯
Focusing

sanjeeb kc kcsanjeeb

🎯
Focusing
  • offix services pvt. ltd.
  • kapan, kathmandu
  • X @sanjeebkc9
View GitHub Profile
@kcsanjeeb
kcsanjeeb / encapsulation.py
Last active July 20, 2020 15:17
code sample 1
class Chocolate:
def __init__(self):
self.__maxprice = 290
def sell(self):
print("Selling Price:{}".format(self.__maxprice))
def setMaxPrice(self, price):
self.__maxprice = price
class Sparrow:
def flight(self):
print("Sparrow can fly")
def swim(self):
print("Sparrow can't swim")
class Penguin:
def flight(self):
print("Penguin can't fly")
def swim(self):
print("Penguin can swim")
class B:
class A:
def a1(self):
print("a1")
class B(A):
def b(self):
print("b")
b = B()
b.a1()
class Adder:
def __init__(self):
self.sum = 0
def add(self,value):
self.sum += value
acc = Adder()
for i in range(99):
acc.add(i)
print(acc.sum)
class A(object):
def a1(self):
print("a1")
class B(object):
def b(self):
print("b")
A().a1()
objectB =B()
objectB.b()
from abc import ABCMeta, abstractmethod
class Section(metaclass=ABCMeta):
@abstractmethod
def describe(self):
pass
class PersonalInfoSection(Section):
def describe(self):
print("Personal information section")
from abc import ABCMeta, abstractmethod
class Employee(metaclass=ABCMeta):
@abstractmethod
def create(self):
pass
class manager(Person):
def create(self, name):
from abc import ABCMeta, abstractmethod
class PizzaFactory(metaclass=ABCMeta):
@abstractmethod
def createVegPizza(self):
pass
@abstractmethod
def createNonVegPizza(self):
pass
class Singleton(object):
def __new__(cls):
if not hasattr(cls, 'instance'):
cls.instance = super(Singleton,cls).__new__(cls)
return cls.instance
s = Singleton()
print("Object created",s)
sA = Singleton()
class Singleton:
__instance = None
def __init__(self):
if not Singleton.__instance:
print("__init__ method is called.")
else:
print("Instance is already created :",self.getInstance())
@classmethod
def getInstance(cls):