0
0
LLDsystem_design~10 mins

Law of Demeter in LLD - Interactive Code Practice

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

Complete the code to follow the Law of Demeter by accessing only immediate friends.

LLD
class Car {
    Engine engine;
    void start() {
        engine.[1]();
    }
}
Drag options to blanks, or click blank then click option'
AgetFuel
BgetPistons
CgetOilLevel
Dignite
Attempts:
3 left
💡 Hint
Common Mistakes
Calling methods on objects returned by other methods (chained calls).
2fill in blank
medium

Complete the code to avoid violating the Law of Demeter by not accessing nested objects directly.

LLD
class Library {
    Book book;
    void printAuthor() {
        System.out.println(book.[1]());
    }
}
Drag options to blanks, or click blank then click option'
AgetPublisher
BgetTitle
CgetAuthor
DgetYear
Attempts:
3 left
💡 Hint
Common Mistakes
Calling methods on objects returned by getPublisher() or deeper.
3fill in blank
hard

Fix the error in the code to comply with the Law of Demeter by removing chained calls.

LLD
class Computer {
    CPU cpu;
    void checkStatus() {
        cpu.[1]();
    }
}
Drag options to blanks, or click blank then click option'
Astart
BgetSpeed
CgetFan
DgetCache
Attempts:
3 left
💡 Hint
Common Mistakes
Using chained calls like cpu.getFan().getTemperature().
4fill in blank
hard

Fill both blanks to rewrite the code so it respects the Law of Demeter by delegating calls.

LLD
class House {
    Kitchen kitchen;
    void clean() {
        kitchen.[1]();
        kitchen.[2]();
    }
}
Drag options to blanks, or click blank then click option'
AcleanSink
BgetFridge
CcleanFloor
DgetOven
Attempts:
3 left
💡 Hint
Common Mistakes
Calling methods on nested objects like getFridge() or getOven().
5fill in blank
hard

Fill all three blanks to refactor the code to follow the Law of Demeter by avoiding chained calls.

LLD
class School {
    Classroom classroom;
    void startClass() {
        classroom.[1]();
        classroom.[2]().[3]();
    }
}
Drag options to blanks, or click blank then click option'
AopenDoor
BgetTeacher
CteachLesson
DgetStudents
Attempts:
3 left
💡 Hint
Common Mistakes
Calling methods on objects returned by getStudents() or chaining deeper than one level.