OOP is a programming paradigm(style) for code organization and design.Object Oriented Programming concept developed in the 1960’s.The OOP paradigm breaks a program in to multiple cooperating objects.Then each object holds some data and functionality.
Students’ score management system involves two objects:
Following is the UML diagram:
Models
class Student:
def __init__(self, name, grade):
self.name = name
self.grade = grade
class Course:
def __init__(self, course, score):
self.course = course
self.score = score
Controllers
from models import Student, Course
class Course_manager(Student, Course):
result = {}
scores = {}
def __init__(self, name, grade, course, score):
Student.__init__(self, name, grade)
Course.__init__(self, course, score)
def add_course(self):
self.scores[self.course] = self.score
self.result[self.name] = self.scores
def show(self):
print(self.result)
Main
from models import Student
from controllers import Course_manager
math = Course_manager('Alex', 4, 'Math', 97)
math.add_course()
physics = Course_manager('Alex', 4, 'Physics', 90)
physics.add_course()
physics.show()
Homework: Design a simple Pong game
Above is a screenshot of a simple Pong game. Please design a simple Pong game. Given requirements blow, try to fulfill as many requirements as possible.
Try to create each components in Python. For example:
models.py
for objectsCreate a main.py
to write the workflow of the game.
You are encouraged to accomplish each requirement to reach the end effect.
happy coding!