I’m pulling in JSON from an external URL. I then want to use that data in two different classes. Here’s how I think it should be setup.
// gets data
class get_data {
}
// creates a widget that uses the data
class widget_class {
}
// some other widget that uses the data
class page_class {
}
How do I get the data from get_data into both widget_class and page_class? I could just insert something like $data = new get_data(); in each class, but that’s not the most efficient way of doing things since it would pull the external data twice, right?
My knowledge of OOP is limited, so any help would be great.
Construct the two classes in tandem using a factory.
The factory is a third class which has a static method returning both a page_class and a widget_class. It makes one get_data call and then appropriately splits up the return as it constructs the two classes.