So, I’m very new to CUBA specifically, but also to the Java world as a whole. I’m the lead programmer for a tiny software company (just 4 of us…) and our application is a whole-office management system for a niche medical industry. It was developed starting in the mid/late 1980’s, in DataFlex (and eventually partially in Visual DataFlex). We needed to convert to a much more modern ecosystem and are very glad we found CUBA.
So far, I’ve developed a fairly major screen in our application - the patient screen - with all the attendant lookup CRUD screens needed to support it (which in CUBA most of those take 30 seconds to develop - amazing!).
This screen probably would have taken a few months to develop in our old world. CUBA cut that to a fraction.
Anyway, getting to my point - I see in several examples/demos things being done as services and sometimes similar things being done directly in the controller. I’m trying to learn to think correctly about these things so that I’m doing things “the right way” and not learning bad habits.
I’ve got things such as up/down buttons for reordering of detail tables, the auto numbering of said tables upon new record insertion, setting of certain defaults when things are chosen from Enumeration lookups - things like that - all done directly in the controller.
I guess what I’m asking is: when is it “necessary” to do things as a service instead? And, if not strictly necessary - when is it desirable?
Hi,
1)
One of advantages of using services is that you can write integration tests for this logic that work with database and test your service as a black box.
You can also write integration tests for web layer of your application, but in these tests you won’t be able to access database, you will have to emulate interaction with database (through DataManager stub).
If you don’t plan to write auto tests in your project, then this advantage doesn’t count.
Another advantage is that logic put to services can be shared between different clients, e.g. between web client and REST API client. Any service method can be exposed through REST API to external clients: 3rd party integrated system or JS client. So if you consider in the future the possibility to write React-based client for you system, you should be preparing for that by putting business logic methods to services.
The guides are good for sure. As I’m still learning how CUBA works, I have a question about this guide - https://www.cuba-platform.com/guides/create-business-logic-in-cuba - there are two classes used, Contact, and ContactType, that I cannot find. I have everything expanded…and they are not there. What am I missing? (I know I can use Go To → Declaration by right clicking, but I’m trying to figure out how to find them in the hierarchy of the project panel…and also where I’d use right-click → new —> etc to do this from scratch.)