Jupyter Notebook ("glue"-code)

Package structure

Package structure

from .controller import *
from .view import *
from .mathengine import MathEngine
class MathEngine:

  def __init__(self):
    '''
    A constructor.
    '''

    print('Really new Math Engine instance.')

  def add(self, number1, number2):
    '''
    Takes 2 integers, and adds them.
    '''

    return number1 + number2

No user interaction here! Just Logic!

from .ui import UI
class UI:

  def __init__(self):
    '''
    '''

    print('New UI')

  def start(self, controller):
    '''
    We ask the user for 2 numbers.
    '''

    print('Please enter number1')
    number1 = input()

    print('Please enter number2')
    number2 = input()

    result = controller.add(int(number1), int(number2))

    print('Result:', result)

UI stuff here that calls the logic!

Package structure

Controller is separate! (All calculations, logic, algorithms  etc.)

View is separate! (All user interactions)

Everything is bundled as one package!

We can import the package and use it!

This was the VC (View and Controller) part of the MVC pattern!

Why structure the code like this?

Remember this!

CS410 Lecture 9b

By Daniel Haehn

CS410 Lecture 9b

Slides for CS410 Software Engineering at UMass Boston. See https://cs410.net!

  • 224

More from Daniel Haehn