Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,151,434 members, 7,812,293 topics. Date: Monday, 29 April 2024 at 11:14 AM

OOP Design Question: Model-View-Controller Pattern - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / OOP Design Question: Model-View-Controller Pattern (2923 Views)

Why Is OOP PHP So Confusing? / How Can I Learn OOP With Java? / A Beginners Guide To Object-oriented Programming (OOP) In PHP 5+ (2) (3) (4)

(1) (Reply) (Go Down)

OOP Design Question: Model-View-Controller Pattern by c0dec(m): 11:23am On Feb 26, 2006
i'm writing an app using the Model-View-Controller pattern and it's got my brain in knots.
It's a 3D simulation with a network mode. (Multiple views of the same data over a network). i figure MVC is the way to go. i've just finished writing a sockets class and about to implement the network component.

the question is where does the network component go? is it a view or a controller? from the way i see it, it could be either (at the moment i'm sticking with it being a view). some with experience would have a better answer.

thanks
Re: OOP Design Question: Model-View-Controller Pattern by Seun(m): 11:46am On Feb 26, 2006
Just a quick question. What exactly does the "network component" you're inventing do?
Re: OOP Design Question: Model-View-Controller Pattern by c0dec(m): 11:58am On Feb 26, 2006
sorry i should said something about the network architecture i'm using.

it's more or less a client-server architecture. an app can either be a client or server (obviously, there can be only one server). it's an architecture that's popular with most LAN games (like unreal tournament) when u can either be a server or client.

that said, the "network component" handles all IP data communication between server and client. (the server's model and it's observers).

Re: OOP Design Question: Model-View-Controller Pattern by Seun(m): 3:16pm On Feb 26, 2006
In my view:
- The MODEL is your 3D Model (easy)
- The Controller is the interface used by clients to manipulate the 3d world.
- The View is what they see.

In my view, the rest is just infrastructure. Including the networking code. This is stuff you can get from off-the-shelf libraries on Sf.net.
Re: OOP Design Question: Model-View-Controller Pattern by c0dec(m): 6:23pm On Feb 26, 2006
nope the model isn't my 3d model. the 3d models are with my view. the model holds the data the view needs to render the 3d models (just as the UML diagram above shows).

but i think i've already figured it out. the network part can either be view or controller. wherever i put it, it'll break the pattern but who cares.

ps: i'm avoiding 3rd party libraries as speed is of the essence so i'm getting as low-level as i possibly can.
Re: OOP Design Question: Model-View-Controller Pattern by sbucareer(f): 11:20pm On Feb 26, 2006


Codec, I have always thought of MVC controller as modelling n-teir application which, is obviously what you are trying to accomplish.

But my understanding and experience with MVC in web application which,  it might as well be used in any software development, is that MVC framework works like this:

View, the software components responsible for rendering the visual aspect of any artefact's. Controller, is responsible for the controlls of all events and actions generated from the view and other automated message within the boundaries of the software. These events could be asynchronous or synchronous.

The Model is the object encapsulation of the software logic ie. the middleware and algometric view of the system.

In your UML above I can see the Model object compsiting the observer object. The Observer Object generalizing the view and Controller object. I can't figure out the design pattern you are employing in this project. If it was Observer pattern which I think it might well be, then observer has to be the controller because it updates the rest of the objects of the changes from the view and the model.

The Model is the model of your system and it encapsulates network, data, and the algometric semantics of your design.


Your system should talk to these three components like this




Reference

1. Design Pattern






Re: OOP Design Question: Model-View-Controller Pattern by c0dec(m): 3:41pm On Feb 27, 2006
sbucareer:

In your UML above I can see the Model object compsiting the observer object. The Observer Object generalizing the view and Controller object. I can't figure out the design pattern you are employing in this project. If it was Observer pattern which I think it might well be, then observer has to be the controller because it updates the rest of the objects of the changes from the view and the model.

The Model is the model of your system and it encapsulates network, data, and the algometric semantics of your design.

I don't know much about the observer pattern but this is how i've got it working.

The Observer is just an interface inherited by view and controller. All observers must implement an update() method.
My controllers modifies the model, My view displays the model. My Model has a list of observers.
During the simulation, my model has a method which loops through all observers calling their update() methods. in the case of the view, it queries the model for data and in case of the controller it updates the model data.

so my question was should the part that handles all network communication be a server or client? but i've figured it can be any. if i run into any problems, i'll ask you guys again.

thanks
Re: OOP Design Question: Model-View-Controller Pattern by Viper(m): 6:24pm On Feb 27, 2006

the question is where does the network component go?

I will tell you, CONTROLLER.
leave view for view
model for model
and controller for controller.
never mix them up for ease in future maintenance of the application.
Re: OOP Design Question: Model-View-Controller Pattern by Otuyelu(m): 7:08pm On Apr 11, 2007
Viper is absolutely right in the theoretically strictest form of MVC, I just wish I can be disciplined enough not to cheat by inserting DB queries into my "views", and generating outputs from my "controllers" because I dont want to spend the 30 minutes to amend a header file.

(1) (Reply)

Have An App Idea? Let's Build Your Next App / Import Dll Into Java Program / Nigeria First Free And Open Source Education Software

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 24
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.