Dependency vs. Association


Managing Conceptual And Physical Complexity

Programs that depend upon the services of multiple classes are inherently more complex than those that do not. This complexity takes two forms: 1) the conceptual complexity derived from the nature of the relationship between or among classes that participate in the design, and 2) the physical complexity that results from having to deal with multiple source files. In this chapter you will encounter programming examples that are both conceptually and physically more complex than previous examples.

You will manage a program’s conceptual complexity by using object-oriented design principles in conjunction with the Unified Modeling Language (UML) to express a program’s design. In this chapter you will learn the concepts of building complex programs using compositional design. You will also learn how to express compositional design using the UML.

The physical complexity of the programs you write in this chapter must be managed through source-file organization. If you have not started to put related project source files in one folder you will want to start doing so. This will make them easier to manage — at least for the purposes of this book. You will also need to change the way you compile your project source files. Until now I have shown you how to compile source files one at a time. However, when you are working on projects that contain many source files, these files may have dependencies to other source files in the project. A change to one source file will require a recompilation of all the other source files that depend upon it.

If you use a Java integrated development environment (IDE) it will manage the source file dependencies automatically. If you are using Sun’s Java Software Development Kit (SDK) you can use an open source build tool like Ant to manage your project’s build process. Ant is used by professional Java developers to manage large project builds. It would be a good idea to learn how to use Ant although a discussion of this tool is beyond the scope of this book. However, if you are interested in Ant I recommend visiting the Ant website. [ http://ant.apache.org/ ] I have also listed a good Ant book in the references section.

But wait! You don’t need to learn Ant right this minute. Read the next section first.

Compiling Multiple Source Files Simultaneously with javac

If you don’t have time to learn Ant and don’t have a fancy schmancy IDE don’t despair. You can compile multiple Java source files simultaneously using the javac compiler tool. All you need to do is enter the names of the source files you want to compile on the command line following the javac command as is shown in the following example:

 javac SourceFileOne.java SourceFileTwo.java SourceFileThree.java

Each source file is listed on the command line one after the other separated by a space. You can compile as many source files as you require using this method.

If you are working on a project that has more than two or three source files then you may want to create a batch file (Windows) or a shell script (Linux, Macintosh OS X) that you can call to perform the compilation for you.

Another way to compile multiple related source files is to put them in a project directory (Which you should be doing anyway!) and use the javac compiler tool as is shown in the following example:

 javac *.java

This will compile all the source files in a given directory. You may, of course, provide an explicit directory path as shown in the following example:

 javac c:\myprojects\project1\*.java

Quick Review

There are two types of complexity: conceptual and physical. Conceptual complexity is managed by using object-oriented design concepts and expressing your object-oriented designs in the Unified Modeling Language (UML). Physical complexity can be managed by your IDE or with an automated build tool such as Ant. You can also manage physical complexity on a small scale by organizing your source files into project directories and compiling multiple files simultaneously using the javac compiler tool.




Java For Artists(c) The Art, Philosophy, and Science of Object-Oriented Programming
Java For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504052
EAN: 2147483647
Year: 2007
Pages: 452

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net