cancel
Showing results for 
Search instead for 
Did you mean: 

What is the best way to handle the loosely coupled way in sapui5 programming?

Jayakrishnan
Active Participant
269

Hi All,

In my custom application development, i have a controller with having more than 1000+ lines of code. I want to separate and put certain logic/implementation from my main controller. Especially the service call, value help implementation etc.

Approach i followed:

I created new control(example ServiceCall.js) and imported the ServiceCall.js in my parent controller.

New Control File: ServcieCall.js:

sap.ui.define([
	"./BaseController",
	"sap/m/MessageToast"
	
], function (BaseController, MessageToast) {
	"use strict";
	var confirmationDialog;
	var oData;
	var i18nModel;
	/**
	 * ServiceCall.js is a control file which is used to sepereate the Creation logic from
	 * the MainController.
	 */
	return {
		
		callCreateGroupFragment: function (oCoreControl, that, sParameter) {
			
	
		}
	


	};
});

Define and implemented the required methods inside the ServiceCall.js.

Then in my parent controller, i just called the ServiceCall control method just using ServiceCall.methodname(arguments).

CreateGroup.callCreateGroupFragment(oCoreControl, this, "actual");


Is this a right way to do or what could be the best way to do this kind of implementation?

Thank you,

Regards,

JK.


Accepted Solutions (1)

Accepted Solutions (1)

WouterLemaire
SAP Mentor
SAP Mentor

I had the same problem with UI5 in the past and came up with the following:

https://blogs.sap.com/2019/12/27/ui5-advanced-programming-model-overview-ui5con-2019/

Enjoy reading and please share your opinion!

Most of the files are not larger than 200 lines but this can be different depending on the project and everything is clearly and understandable separated. Hoot helps!

Jayakrishnan
Active Participant

Thanks c3d1947136cd4c748a7aa794001af496 , yes i referred some of your blog related to handle is MVC effectively. Thanks for your view on this. Bu in my question, i stated that they way i called the js file,without instantiating Directly, is that right?

Or Should i need to go for ManagedObject extend or Object extend.

Regards,

JK.

WouterLemaire
SAP Mentor
SAP Mentor

Without instantiating can be helpful in case you need to extend it later.

I would definitely go for extend on ManagedObject or Object. I used Object because it can be used in a more generic way. In the ManagedObject, you need to define the parameters upfront.

Jayakrishnan
Active Participant
0 Kudos

Thank you.

Answers (1)

Answers (1)

Sharathmg
Active Contributor
0 Kudos

firstly, appreciate that you are attempting to modularize the code. But be also careful of loading multiple files compared to single file. With component-preload file loading of files is improved so go for decoupling only when it makes clear benefit especially in terms of reuse or maintenance.

Regards.

Jayakrishnan
Active Participant
0 Kudos

Thanks sharath.mg for your comments.

instead of adding component-preload.js, i declared the dependencies lib in the app descriptor. Is it same or what can we add in the Component-preload.js?

Thanks,

Regrads,

JK.