My colleague likes connecting OOP to how things work in the actual, but a bit too much and sometimes I believe in an awkward way.
Instance 1:
He always suggests not to use static variables to track all instances but create another class and then create an array in that class to do all that what could have been done using only a single static variable (of course with proper privileges). So, say I have a class called "Card", according to him I should not be using a static variable to track cards but have another class called "CardsList" and create an array inside this class "CardsList" to keep track of the cards.
//in the main class
private CardsList Cards = new CardsList();
//in CardsList class
static List<card> CardsList = new ArrayList<>();
vs
//in the cards class
static List<card> CardsList = new ArrayList<>();
Instance 2:
If we were to create a simple stock market simulation.
I would prefer creating a class called market and store pending orders of that market in an array in that very class class market.
He on the other hand wants me to create a class named PendingOrders containing nothing but an array and doing nothing but what the array was doing in the class market. Something like this:
//in the market class
private PendingOrders pendingOrders = new PendingOrders();
//in the PendingOrders class
private List<order> pendingOrders = new ArrayList<order> ();
vs
//in the market class
private List<order> pendingOrders = new ArrayList<order> ();
The answers he gives to reason his approach are completely useless, and I think he is blindly following what someone else had told him.
Can someone help me compare the two approaches? And when can one be more beneficial over the other?
Aucun commentaire:
Enregistrer un commentaire