Explain MVC in SAPUI5. Where does each part live in a real project, and where do you put logic that several controllers share?
Say your answer out loud first.
Practise another way
In SAPUI5 the view defines the UI, usually as an XML view. The model holds the data, for example an OData V4 or JSON model declared in manifest.json. The controller reacts to events and works with the model and the view.
Each view has a controller with the matching name, like Detail.view.xml and Detail.controller.js. Logic several controllers need goes into a BaseController they extend, and formatters go into their own module, not copied into each controller.
MVC in UI5 is about separation: SAP's guide says it lets you change the view without touching business logic and show several views of the same data.
The three parts
- View: SAP strongly recommends XML views (and fragments). Tags map to controls, attributes to properties, and bindings connect them to data. XML keeps the view free of logic and can be edited by tools.
- Model: holds the data and the methods to read and change it. For remote data use the OData V4 model on new projects (OData V2 for older services); JSON models for small client-side data. Declare models in
sap.ui5/modelsinmanifest.json, not in code. - Controller: reacts to view events (a button's
press), reads and changes models, navigates. One controller per view, matching names:Detail.view.xmlandDetail.controller.js(or.ts).
What ties it together
Component.js is the app's entry point and loads manifest.json, which declares models, routing and dependencies. In the launchpad the component is started directly; index.html is only for running the app standalone.
webapp/
Component.js
manifest.json
controller/BaseController.js
controller/List.controller.js
view/List.view.xml
model/formatter.js
i18n/i18n.properties
Shared logic
SAP's guidance names the BaseController: a controller not tied to a view, which other controllers extend, holding helpers such as getRouter(), getModel(name) or getResourceBundle().
Formatter functions go into a module in the model folder, used only when expression binding is not enough. For bigger reuse across apps, a reuse library or component is the next step.
sap.ui.define(["./BaseController"], (BaseController) => {
"use strict";
return BaseController.extend("zapp.controller.List", {
onPress(oEvent) {
const sId = oEvent.getSource().getBindingContext().getProperty("OrderID");
this.getRouter().navTo("detail", { id: sId });
}
});
});
What an ABAP developer should add
In Fiori elements apps you write almost no controller code: the model is the OData service from your RAP service binding, and the view is generated from annotations. MVC still matters for extensions (controller extensions, custom sections) and freestyle apps.
Names XML views, models in manifest.json and controllers by file, and mentions BaseController and formatter modules for reuse.
Recites 'model, view, controller' without saying what goes where, or puts data access and formatting inside every controller.
Putting business logic or service calls in the view, or copying the same helper into every controller instead of a BaseController.
- Why does SAP prefer XML views over JS views?
- Where do you declare the OData model, and why not in the controller?
- What is Component.js for, and when is index.html not used?
2 candidate write-ups, 1 official page and 3 prep guides. Confidence: high. Checked 1 Dec 2026.
- Official page Backs the answer.
- Candidate write-up Describes the round.
- Candidate write-up Gives the question.
- Prep guide Gives the question.
- Prep guide Gives the question.
- Prep guide Gives the question.