Relative Content

Tag Archive for object-oriented

How to avoid init methods when 2 objects need the reference of each other?

According to https://softwareengineering.stackexchange.com/a/334972/432039, I know init is a code smell and should be avoided, and one of the solutions is to use a builder to hold the state first instead of create the object first and then set the state, like https://softwareengineering.stackexchange.com/a/452495/432039 mentions, eg:

Which language should I study, c++ or java?

I’m a freshman in computer science at university and I learned procedure-oriented programming in C language. Now I’m going to learn object-oriented programming. Which language do you recommend, java or c++? And why? I’d really appreciate it if you could elaborate.

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.

Defining functions inside vs outside a class

Say I have a class with a function do_thing that is comprised of multiple steps, which themselves segregate into functions (first_process and second_process). At what point would this be considered bad practice, particularly if you have several composite do_thing functions?

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.

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.