14.01.2020 Views

ABAP_to_the_Future

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

The Model-View-Controller Concept 12.1

a general rule, if you have two choices regarding how to do something, then you

should usually veer toward the one that follows the OO principles.

Model Declared in the Controller

This leaves one last option: declaring th e model in the controller. If you declare

the model class in the main controller, it is instantiated right at the start when the

controller is being created. That migh t be a backward-looking attitude, but it

beats the other two options into a cocked hat: there is a clear separation of concerns

and there is no way the view can know about the model and vice versa—so

you can change one without having to ch ange the other. This should make OO

purists bounce up and down with joy, so this is the approach taken in the example

later in this chapter.

12.1.2 View

A view is a part of the program that brings data up on the screen for the user to

look at or interact with. The best examples inside SAP are functions such as

REUSE_ALV_GRID or classes such as CL_SALV_TABLE. The job of a view is very simple

in one sense; it displays data and controls what sort of commands a user can perform

based on that data. Where this beco mes an art form is that the view must

present this information in a way that do es not make the user physically sick.

Thus far, the vast majority of applications have failed in this task.

In an ideal world, a view would be totally generic, like an ALV grid: pass in any

internal table you want, and the view will display it in the best way it knows how.

Note

Just to confuse you totally, there are two elements that correspond to the classical definition

of the term “view” in WDA: windows and views. The important thing to remember

is that windows are the glue that stick views together. A window is like an empty

fridge door onto which you stick several fridge magnets (the views).

If you can think of the window in WDA as sort of the same as an empty main screen in

classical DYNPRO and the view as a DYNPRO subscreen, then you will recognize the

same sort of concepts. (Now, some WDA fa ns are going to be foaming at the mouth

with rage and chasing me from the town with tar and feathers, screaming “It’s completely

different!” Maybe it is, but drawing analogies always helps me understand things

better; maybe it will help you also.) Hereafter, when this chapter refers to views, it is

referring to WDA views. When it refers to WDA windows, it will specifically say so.

511

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

Saved successfully!

Ooh no, something went wrong!