Passing Objects via Dependency Injection

Medium Composition & Aggregation
Solve in Playground →

Problem Statement

Create a `Database` class with a `db_name` attribute. Create a `Server` class whose `__init__` requires a `Database` object passed into it. Print ‘Server connected to [db_name]’.

Input Format

A single string for the database name.

Output Format

Print the connection message.

Constraints

None

Sample Input

PostgreSQL

Sample Output

Server connected to PostgreSQL

Explanation

Dependency Injection is a common form of aggregation where a class receives its dependencies from the outside rather than creating them internally.

Starter Code

class Database:
    pass

class Server:
    pass

if __name__ == '__main__':
    db_n = input().strip()
    # Inject Database into Server
    pass

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used