Designing by Declaration

User interfaces can be designed using one of two methods: procedural and declarative. Procedural simply means in code. For example, when you're programming a Swing application, you write Java code to create and manipulate all the user interface objects such as JFrame and JButton. Thus, Swing is procedural.

Declarative design, on the other hand, does not involve any code. When you're designing a simple web page, you use HTML, a markup language similar to XML that describes what you want to see on the page, not how you want to do it. HTML is declarative.

Android tries to straddle the gap between the procedural and declarative worlds by letting you create user interfaces in either style. You can stay almost entirely in Java code, or you can stay almost entirely in XML descriptors. If you look up the documentation for any Android user interface component, you'll see both the Java APIs and the corresponding declarative XML attributes that do the same thing.

Which should you use? Either way is valid, but Google's advice is to use declarative XML as much as possible. The XML code is often shorter and easier to understand than the corresponding Java code, and it's less likely to change in future versions.

ÏÏÈDS 5:51 PM

Game

3 6

4

2

3

8

4

2

7

4

6

3

8 2

1

4

5

1

3

2

1

9

7

4

8

3

4

5

Figure 3.1: The Sudoku example program for Android

Now let's see how we can use this information to create the Sudoku opening screen.

0 0

Post a comment