jeudi 13 avril 2023

How to pass data to child objects from a controller style class

Given I have a sort of controller class which needs to setup some other objects e.g.

class ControllerClass
{
private someData: DataClass[];

private doSomeWorkOnData(): void
{
this.someData.foreach((value) =>
{
someData.doWork(//pass in values);
}
}
}

class DataClass
{
// Should these classes have their own version of the data?
public readonly numberData: number = 32;
public readonly stringData: string = "something";

public doWork(//pass in values): void{}
}

My question is should the data for the above variables in the DataClass be passed in each time so that the ControllerClass has the only copy of them saving space, or should each of the DataClasses have their own version of it even though they never change. I feel like that approach simplifies the code but makes it very memory intensive for no real reason.

Both of them work fine, but is either memory intensive or slightly messy looking.

Aucun commentaire:

Enregistrer un commentaire