0
0
Microservicessystem_design~10 mins

Domain-Driven Design (DDD) basics in Microservices - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to identify the core building block of DDD that represents a real-world concept.

Microservices
class [1]:
    def __init__(self, id, name):
        self.id = id
        self.name = name
Drag options to blanks, or click blank then click option'
ARepository
BService
CEntity
DFactory
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing Entities with Services or Repositories.
2fill in blank
medium

Complete the code to define a DDD pattern that encapsulates domain logic without identity.

Microservices
class [1]:
    def calculate_discount(self, amount):
        return amount * 0.1
Drag options to blanks, or click blank then click option'
AValueObject
BEntity
CRepository
DAggregate
Attempts:
3 left
💡 Hint
Common Mistakes
Using Entity instead of Value Object for simple data.
3fill in blank
hard

Fix the error in the code to correctly represent a DDD Repository interface.

Microservices
class User[1]:
    def find_by_id(self, user_id):
        pass
Drag options to blanks, or click blank then click option'
AService
BAggregate
CFactory
DRepository
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing Repository with Service or Factory.
4fill in blank
hard

Fill both blanks to complete the Aggregate root pattern that controls access to related Entities.

Microservices
class Order[1]:
    def __init__(self, order_id):
        self.order_id = order_id
        self.items = []

    def add_item(self, item):
        self.items[2](item)
Drag options to blanks, or click blank then click option'
AAggregate
Bappend
Cextend
DService
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'extend' instead of 'append' to add a single item.
5fill in blank
hard

Fill all three blanks to complete a DDD Service method that processes a payment.

Microservices
class Payment[1]:
    def process(self, amount, method):
        if method == 'credit_card':
            return self.[2](amount)
        else:
            return self.[3](amount)

    def charge_credit_card(self, amount):
        pass

    def charge_paypal(self, amount):
        pass
Drag options to blanks, or click blank then click option'
AService
Bcharge_credit_card
Ccharge_paypal
DRepository
Attempts:
3 left
💡 Hint
Common Mistakes
Using Repository instead of Service for business logic.