classVsInstance

Educational Python implementation demonstrating class vs instance variables and basic OOP logic.

https://github.com/davidbmar/classVsInstance  ·  public  ·  shipped

What it is

A Python coding challenge solution that defines a Person class to manage age validation, state progression over time, and categorical status reporting (young, teenager, old). It serves as a practical example of object-oriented principles, specifically distinguishing between class-level and instance-level data and behavior.

Features

Quickstart

python person.py

Architecture

flowchart TD
    A[Main Driver] -->|Input Age| B(Person Constructor)
    B -->|Validate Age| C{Age < 0?}
    C -->|Yes| D[Set Age = 0]
    C -->|No| E[Set Age = Input]
    D --> F[Print Warning]
    E --> G[Store Instance Variable]
    F --> H[Person Instance]
    G --> H
    H -->|Call| I[amIOld]
    H -->|Call| J[yearPasses]
    I --> K[Print Status]
    J --> L[Increment Age]

How it's built

The project consists of a single Python module defining a `Person` class. The class includes an `__init__` constructor for validation, a `yearPasses` method to mutate state, and an `amIOld` method for conditional output. It relies on standard Python control flow and print statements, designed to interface with a provided stub/main driver for testing.

How it runs

sequenceDiagram
    participant Main as Main Driver
    participant P as Person Instance
    Main->>P: __init__(initialAge)
    alt initialAge < 0
        P->>P: self.age = 0
        P->>Main: Print 'Age is not valid...'
    else initialAge >= 0
        P->>P: self.age = initialAge
    end
    Main->>P: amIOld()
    P->>Main: Print Status (Young/Teen/Old)
    Main->>P: yearPasses()
    P->>P: self.age += 1
    Main->>P: amIOld()
    P->>Main: Print Updated Status

How to apply & reuse

Integrate the `Person` class into Python learning modules, OOP tutorials, or automated grading systems for introductory programming courses. Use it as a reference for implementing validation logic within constructors and managing object state transitions.

At a glance

CapabilitiesAge validationState mutationConditional loggingObject instantiation
ComponentsPerson ClassConstructorInstance MethodsMain Stub
TechPython 3OOP
Depends on
Integrates with
PatternsConstructor ValidationState PatternEncapsulation
Reuse tagseducationoop-basicspython-examplecoding-challenge

Repo hygiene

✓ all on main — nothing unmerged.