Skip to main content

Small library for observation mechanism

Project description

ntt-command-service

Library for implementing Command Pattern

Examples

from ntt_command_service import *
from typing import List

fScores: List[float] = []

class AppendDataCommand(ICommand):
    def __init__(self, fScores: List[float], fScore: float):
        self._fScores = fScores
        self._fScore = fScore

    def Execute(self) -> None:
        self._fScores.append(self._fScore)

    def CanExecute(self) -> bool:
        return True

    def Undo(self) -> None:
        self._fScore.pop()

serCommandService = CommandService()
serCommandService.AddCommand(AppendDataCommand(fScores, 3))
# ----> fScores = [3]
serCommandService.AddCommand(AppendDataCommand(fScores, 5))
# ----> fScores = [3, 5]
serCommandService.AddCommand(AppendDataCommand(fScores, 1))
# ----> fScores = [3, 5, 1]
serCommandService.Undo()
# ----> fScores = [3, 5]
serCommandService.Clear()
serCommandService.CanUndo()
# ----> False

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ntt-command-service-1.0.4.tar.gz (4.0 kB view hashes)

Uploaded Source

Built Distribution

ntt_command_service-1.0.4-py3-none-any.whl (5.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page