Skip to content

Instantly share code, notes, and snippets.

Gergo Bogdan gergob

Block or report user

Report or block gergob

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@gergob
gergob / Gadget3.py
Created Nov 21, 2014
Gadget without respecting OOP encapsulation
View Gadget3.py
my_iphone = Gadget(weight = 128, operating_system="iOS", battery_capacity=2800, screen_size=4)
print(my_iphone.weight)
print(my_iphone.operating_system)
print(my_iphone.battery_capacity)
print(my_iphone.screen_size)
@gergob
gergob / Gadget.py
Last active Aug 29, 2015
Gadget python class
View Gadget.py
class Gadget:
weight = 100
operating_system = None
battery_capacity = 2000
screen_size = 1
my_iphone = Gadget()
@gergob
gergob / p_gadget_console.txt
Created Nov 21, 2014
using Gadget python class
View p_gadget_console.txt
>>> from Gadget import Gadget
>>> my_iphone = Gadget(240,'iOS',1980,4)
>>> my_iphone.weight
240
>>> my_iphone.weight = 255
>>> my_iphone.weight
255
>>>
>>>
>>> my_iphone.operating_system
@gergob
gergob / Gadget2.py
Created Nov 21, 2014
Gadget class with constructor
View Gadget2.py
class Gadget:
weight = 100
operating_system = None
battery_capacity = 2000
screen_size = 1
def __init__(self, weight, operating_system, battery_capacity, screen_size):
self.weight = weight
self.operating_system = operating_system
self.battery_capacity = battery_capacity
View Gadget_encapsulation.py
class Gadget:
"""A class used for modelling Gadgets in a web shop."""
__weight = 100
__operating_system = None
__battery_capacity = 2000
__screen_size = 1
def __init__(self, weight, operating_system, battery_capacity, screen_size):
self.__weight = weight
self.__operating_system = operating_system
@gergob
gergob / animal.py
Created Nov 26, 2014
Animal class implemented in Python 3.x
View animal.py
class Animal:
__name = None
__age = 0
__is_hungry = False
__nr_of_legs = 0
def __init__(self, name, age, is_hungry, nr_of_legs):
self.name = name
self.age = age
self.is_hungry = is_hungry
@gergob
gergob / multiple_inheritance_in_action.py
Created Nov 26, 2014
Multiple Inheritance SmartPhone class in action
View multiple_inheritance_in_action.py
#
# will be discussed later why only the constructor of Phone class was invoked
#
>>> my_iphone = SmartPhone()
Phone constructor invoked.
>>> my_iphone.call_number("123456789")
Calling number 123456789
>>> my_iphone.install_software("python")
@gergob
gergob / multiple_inheritance.py
Created Nov 26, 2014
Phone, Computer, SmartPhone classes implemented using multiple inheritance in Python 3.x
View multiple_inheritance.py
class Phone:
def __init__(self):
print("Phone constructor invoked.")
def call_number(self, phone_number):
print("Calling number {}".format(phone_number))
@gergob
gergob / snake.py
Created Nov 26, 2014
Snake class implementation in Python 3.x
View snake.py
class Snake(Animal):
__temperature = 28
def __init__(self, name, temperature):
super().__init__(name, 2, True, 0)
self.temperature = temperature
#
# METHODS
#
@gergob
gergob / oop_multi.py
Created Dec 8, 2014
multiple_inheritance_manual_constructor
View oop_multi.py
class Phone(object):
def __init__(self):
print("Phone constructor invoked.")
def call_number(self, phone_number):
print("Calling number {}".format(phone_number))
You can’t perform that action at this time.