vendredi 1 février 2019

MVC - Should be there a master View, Model and Controller or should they be implementation-specific?

I'm interested in the concept, not the implementation. Consider a CarBookingRequest scenario where user through an interface requests for booking a car. Let's discuss it under the following constraint and taking only View in perspective by keeping Controller and Model simple:

  • There is one controller class/code which contains all the functions representing relevant actions
  • There is one model class/code that deals only with single database with few tables (no other data models)

There can be many interfaces through which a request can be made:

1. Desktop Application

A user clicks a Button that fires the Click event which in turn is pre-programmed to make a call to BookingController with request NewBooking. Something like:

 Event OnClick() { 
    C = New BookingController
    C.Request('NewBooking')
 }

2. Mobile Application

A user taps a Button that fires the Touch event which in turn is pre-programmed to make a call to the same BookingController with request NewBooking. Something like:

 EventListener OnTouch() { 
    C = New BookingController
    C.Request('NewBooking')
 }

3. Vending Machine

A user presses a PushButton on the machine that fires the event which is pre-programmed to make a call to the same BookingController with request NewBooking. Something like:

 Event OnPress() { 
    C = New BookingController
    C.Request('NewBooking')
 }

Assume similar implementation for a Web Interface and Service Interface where the request is made by another system or a scheduled task. Obviously all these implementation are different versions of BookingViews written in very different languages and platform. Now if I knew these implementations beforehand and I am making a Booking MVC, what should be my View, Controller and Model Class like? or how many? and why?

Should I have a "Main" BookingView class that has a function such as:

 Function CallController(Command) { 
    If Command = 'NewBooking' {
       Return New BookingController
    }
    or some good implementation of controller/action registry to fetch appropriate controller
 }

and every specific View should in-turn call this function which then will call the BookingController as:

 Event OnClick { 
    C = MainView.CallConroller('NewBooking')
 }

Or should each View call the controller separately in its own way?

May be too many questions but I am of the view that my View, Controller and Model should be reusable and every new Interface (Mobile, Machine or Web) should require only their specific handling of the View (events or displays) while the connecting and fetch data code remains untouched.

Aucun commentaire:

Enregistrer un commentaire