Relative Content

Tag Archive for composition

Composition vs. Inheritance [duplicate]

This question already has answers here: Designing a library that is easy to use: composition or inheritance (2 answers) Closed 11 years ago. Here’s what is given: public interface Request {} // there are 20 subclasses of Request public class CreateUserRequest implements Request { @NotEmpty public String userName; } // request processor is a thing […]

Is this an example of a composition or aggregation? [duplicate]

This question already has answers here: Aggregation vs Composition (9 answers) Closed 7 years ago. Composition and aggregation both are confusion to me. Does my code sample below indicate composition or aggregation? class A { public static function getData($id) { //something } public static function checkUrl($url) { // something } class B { public function […]

What is the correct way of implementing state machine design pattern via composition?

I am trying to implement a VendingMachine which has multiple states (Idle, ProductSelected, ReceivedMoney, ProductDispatched). Each state implements method in VendingMachineState (for simplicity consider just collectMoney(int amount)). Methods like collectMoney() do their job and then change the state to the next state as per the state machine.

If an entity is composed, is it still a god object?

I am working on a system to configure hardware. Unfortunately, there is tons of variety in the hardware, which means there’s a wide variety of capabilities and configurations depending on what specific hardware the software connects to.