Skip to content

Instantly share code, notes, and snippets.

View rdcoder33's full-sized avatar

Raj Dhakad rdcoder33

View GitHub Profile
from abc import ABC, abstractmethod
class Shape(ABC):
@abstractmethod
def area(self):
pass
@abstractmethod
from abc import ABC, abstractmethod
class Shape(ABC):
@abstractmethod
def area(self):
pass
@abstractmethod
class Shape:
def area(self):
pass
def perimeter(self):
pass
class Square(Shape):
class Robot:
def __init__(self, name, model_no, creator):
self.name = name
self.model_no = model_no
self.creator = creator
def walk(self):
return 'I am walking using my wheels'
class Book:
def __init__(self, name, author, publisher):
self.name = name
self.author = author
self.publisher = publisher
def book_details(self):
return f'{self.name} by {self.author} from {self.publisher}'
@rdcoder33
rdcoder33 / composition.py
Last active December 27, 2018 04:37
Example of Composition
class Book:
def __init__(self, name, author, publisher):
self.name = name
self.author = author
self.publisher = publisher
def book_details(self):
return f'{self.name} by {self.author} from {self.publisher}'
class Rectangle:
sides = 4
all_sides_equal = False
opposite_sides_equal = True
type = 'rectangle'
def area(self):
length = int(input('Enter length: '))
width = int(input('Enter width: '))
return length * width
class Superclass:
super_class_call = 0
def class_call(self):
print('I am Superclass')
self.super_class_call += 1
class ClassA(Superclass):
class Superclass:
super_class_call = 0
def class_call(self):
self.super_class_call += 1
print('I am Superclass')
class ClassA(Superclass):
class Superclass:
def class_names(self):
return 'I am super class'
class ClassA(Superclass):
def class_names(self):
return 'I am class A'