Hi Deepak,
I understand that you want to implement a Model-Controller pattern where the controller has access to the model but there is no direct communication between the view and the model (i.e., no use of notifications or events), you can design your system in a way that the view only communicates with the controller, and the controller handles all interactions with the model.
Here's a simplified outline of how you might structure your code:
- The model contains the data and the logic of your application. It does not know about the controller or the view.
function obj = Model(data)
function data = getData(obj)
function obj = setData(obj, newData)
- The controller has access to the model and can retrieve or update data. The controller also processes user input from the view and updates the view accordingly.
function obj = Controller(model, view)
obj.View.Controller = obj;
function updateModel(obj, newData)
obj.Model.setData(newData);
data = obj.Model.getData();
obj.View.displayData(data);
- The view is responsible for displaying the data. It receives user input and notifies the controller but does not interact with the model directly.
function displayData(obj, data)
function userAction(obj, newData)
obj.Controller.updateModel(newData);
- You can tie these components together as follows:
model = Model(initialData);
controller = Controller(model, view);
controller.updateModel(newData);
view.displayData(controller.Model.getData());
Hope this helps.