14.01.2020 Views

ABAP_to_the_Future

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

12

Web Dynpro ABAP and Floorplan Manager

is to change the model (although the latte r is not impossible either). Therefore,

putting the model inside the view is no t the way forward; the model should go

nowhere near this area. (Strangely, ithas been said that “SAP forbids SELECT statements

within views,” but this is not enforced by the syntax check—you don’t get

a warning and it all works fine. So by “forbid,” it would seem that SAP presumes

that you won’t do it if you’re told not to.)

Another recommendation is to not put any references to the model class (or any

SELECT statements) in the view. Even if it is technically possible to do so, it paints

you into a corner. You will see later on in this chapter how you use the code in

the view to delegate tasks upwards (which, as an aside, is exactly what you do in

classical DYNPRO modules as well).

Model as an Assistance Class

Using the model as an assistance class isanother option. A WDA application looks

somewhat like a tree structure, and right at the top you can declare an assistance

class. This class then pops up automatically as a member variable of all the controllers

within the application.

At first glance, this looks like the idea l place to put your model class, and some

articles about WDA suggest just this approach. However, housing a model class

does not seem to be what an assistance class was intended to do; its purpose

seemed to be very WDA-specific and to revolve around handling texts (such as

field labels) throughout the application. If you’re a pu rist, you’d also be uncomfortable

with one class doing two dispar ate things; this would mean that you

would have to make your model inherit from a WDA-specific abstract class. Your

model class would then be tightly coupled to the WDA framework (the opposite

of what you generally want to achieve) as well as doing two different things:

model-type things and WDA-specific text things.

It is also possible to use the assistance class as a go-between linking the real model

to the WDA application. In this scenario, the assistance class would still be doing

two things, but you could reuse existing models and they would not be tied to the

WDA framework. However, if you take this approach, then the views can call the

model methods directly, and you are back to the problem with the model and the

view tied together, so it is difficult to change one without the other. It seems that

all those OO books (see the end of the chapter for some recommendations) actually

put in all these rules about separation of concerns for a very good reason. As

510

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!