Springer Optimization and Its Applications VOLUME 93 Managing Editor Panos M. Pardalos (University of Florida) Editor Combinatorial Optimization Ding-Zhu Du (University of Texas at Dallas) Advisory Board J. Birge (University of Chicago) C.A. Floudas (Princeton University) F. Giannessi (University of Pisa) H.D. Sherali (Virginia Polytechnic and State University) T. Terlaky (McMaster University) Y. Ye (Stanford University) Aims and Scope Optimization has been expanding in all directions at an astonishing rate during the last few decades. New algorithmic and theoretical techniques have been developed, the diffusion into other disciplines has proceeded at a rapid pace, and our knowledge of all aspects of the field has grown even more profound. At the same time, one of the most striking trends in optimization is the constantly increasing emphasis on the interdisciplinary nature of the field. Optimization has been a basic tool in all areas of applied mathematics, engineering, medicine, economics, and other sciences. The series Springer Optimization and Its Applications publishes undergraduate and graduate textbooks, monographs and state-of-the-art expository works that focus on algorithms for solving optimization problems and also study applications involving such problems. Some of the topics covered include nonlinear optimization (convex and nonconvex), network flow problems, stochastic optimization, optimal control, discrete optimization, multi-objective programming, description of software packages, approximation techniques and heuristic approaches. For further volumes: http://www.springer.com/series/7393
Petraq J. Papajorgji Panos M. Pardalos Software Engineering Techniques Applied to Agricultural Systems An Object-Oriented and UML Approach Second Edition 123
Petraq J. Papajorgji Canadian Institute of Technology Tirana, Albania Panos M. Pardalos Department of Industrial and Systems Engineering University of Florida Gainesville, FL, USA ISSN 1931-6828 ISSN 1931-6836 (electronic) ISBN 978-1-4899-7462-4 ISBN 978-1-4899-7463-1 (ebook) DOI 10.1007/978-1-4899-7463-1 Springer New York Heidelberg Dordrecht London Library of Congress Control Number: 2014938623 First edition published by Springer 2006 in Applied Optimization, Vol. 100 Mathematics Subject Classification (2010): 68, 94 Springer Science+Business Media New York 2006, 2014 This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Exempted from this legal reservation are brief excerpts in connection with reviews or scholarly analysis or material supplied specifically for the purpose of being entered and executed on a computer system, for exclusive use by the purchaser of the work. Duplication of this publication or parts thereof is permitted only under the provisions of the Copyright Law of the Publisher s location, in its current version, and permission for use must always be obtained from Springer. Permissions for use may be obtained through RightsLink at the Copyright Clearance Center. Violations are liable to prosecution under the respective Copyright Law. The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Printed on acid-free paper Springer is part of Springer Science+Business Media (www.springer.com)
To our children: Dea Petraq Papajorgji and Miltiades Panos Pardalos
Preface to the Second Edition The first edition of this book was used as a textbook in several universities around the world. We have received comments and suggestions on how to improve the book. As the first edition was published in 2006, it is fitting that after 9 years there are many technological changes and advances that must be presented. For one thing, UML, which is at the heart of the approach used in the first edition, is in version 2. The new version of UML is more complete; it is enriched with the object constraint language (OCL) to better express constraints on modeling elements. This second edition has a dedicated chapter about OCL. The framework-based software development is one of the most important approaches nowadays; it is powerful and enormously facilitates the process of software development. There are a few such frameworks such as Zend Framework (http://www.framework.zend.com) and Yii (http://www.yiiframework.com) to name a couple. At the center of this framework-based approach is the model-viewcontroller (MVC) design pattern. Therefore, we have dedicated a special section to the presentation of the MVC pattern. In the Epilogue of the first edition we had predicted that the model-driven architecture (MDA) approach would grow and play a relevant role in the software development industry. Our prediction was right. MDA is becoming more and more prevalent in the software industry. Several MDA compliant tools have been present in the market and its share in the software development industry is growing constantly. One cannot write a serious book on software development without mentioning this approach. In this book, we have selected to introduce only two of the MDA-based tools the virtual enterprise (http://www.intelliun.com) and Oliva Nova (http://www.integranova.com). Two new chapters present some details of these important technologies. To write a book about software engineering is very challenging as technologies change continuously and books in this domain usually do not have a long shelf life. We paid special attention to not get into the details of the implementation of a particular technology but rather in presenting the modeling part of the problem. Models are abstract and technology independent. Therefore, models have a long shelf life. vii
viii Preface to the Second Edition Chapter 8 includes exercises and questions on conceptual modeling. The corresponding answers are given in Chap. 16 at the end of the book. The goal is to make readers aware that modeling is a complex task and the essence of the object-oriented paradigm must be understood before starting to model. The book can be useful to undergraduate and graduate students and researchers who have an interest on modeling complex systems. A book is never the result of the author s work only, and this book does not make exception from this general rule. Several are they who deserve credit for their objective and unselfish help that made this book better. We would like to express our gratitude to all of them for their criticism and suggestions that contributed to improve the quality of our work.
Preface to the First Edition This book is an effort to bring the application of new technologies into the domain of agriculture. Historically, agriculture has been relatively behind the industrial sector in using and adapting to new technologies. One of the reasons for the technological gap between industrial and agricultural sectors could be the modest amounts of investments made in the field of agriculture compared to the impressive numbers and efforts the industrial sector invests in new technologies. Another reason could be the relatively slow process of updating the student s curriculum with new technologies in university departments that prepare our future specialists in the field of agriculture. With this book, we would like to narrow the technological gap existing between agriculture and the industrial sector in the field of software engineering. We have tried to apply modern software engineering techniques in modeling agricultural systems. Our approach is based on using the object-oriented paradigm and the unified modeling language (UML) to analyze, design, and implement agricultural systems. Object-oriented has been the mainstream approach in the software industry for the last decade, but its acceptance by the community of agricultural modelers has been rather modest. There are a great number of researchers who still feel comfortable using traditional programming techniques in developing new models for agricultural systems. Although the use of the object-oriented paradigm will certainly not make the simulation models predict any better, it will surely increase the productivity, flexibility, reuse, and quality of the software produced. The success of the object-oriented approach is mostly due to the ability of this paradigm to create adequate abstractions. Abstraction is an effective way to manage complexity as it allows for focusing on important, essential, or distinguishing aspects of a problem under study. Object-oriented is the best approach to mimic real world phenomena. Entities or concepts in a problem domain are conceived as objects provided with data and behavior to play a well-defined role. Objects can represent anything in the real world, such as a person, a car, or a physiological process occurring in a plant. The use of objects enormously facilitates the process of conceptual modeling, which can be defined as the process of organizing our ix
x Preface to the First Edition knowledge of an application domain into orderings of abstractions to obtain a better understanding of the problem under study. Conceptual modeling makes heavy use of abstraction, and the object-oriented approach, unlike other programming paradigms, provides direct support for the principle of abstraction. Currently, UML is an industry standard for visualizing, specifying, constructing, and documenting all the steps of the software development. UML allows for presenting different views of the system under study using several diagrams focusing on the static and the dynamic aspects of the system. UML can be used in combination with a traditional programming environment, but its power and elegance fits naturally with the object-oriented approach. One of the most beneficial advantages of UML is its ability to design a platform independent model (PIM) that is a representation of the model using a high level of abstraction. Details of the model can be expressed clearly and precisely in UML as it does not use any particular formalism. The intellectual capital invested in the model is insulated from changes in the implementation technologies. A platform specific model (PSM) is developed by mapping a PIM to a particular computer platform and a specific programming environment. A mapping process allows the transformation of the abstract PIM into a particular PSM. This two-layer concept, a PIM and the corresponding PSM, keeps the business logic apart from the implementation technologies. Experience shows that the business logic has a much longer life than the implementation technologies. Changes and evolution of the implementation technologies should not have any impact on the business model. The book is divided into two parts. Part one presents the basic concepts of the object-oriented approach, their UML notations, and an introduction to the UML modeling artifacts. Several diagrams are used to present the static and dynamic aspects of the system. There are an ample number of examples taken from the agriculture domain to explain the object-oriented concepts and the UML modeling artifacts. In this part of the book, a short introduction to design patterns explains the need for using proven solutions to agricultural problems. Part two deals with applying the object-oriented concepts and UML modeling artifacts for solving practical and real problems. Detailed analysis are provided to show how to depict objects in a real problem domain and how to use advanced software engineering techniques to construct better software. Examples are illustrated using the Java programming language. The book aims to present modeling issues a designer has to deal with during the process of developing software applications in agriculture. Although the Java programming language is used to illustrate code implementation, this book is not intended to teach how to program in Java. For this topic, we would recommend the reader to look for more specialized books. There is a chapter in this book that introduces the reader to some of the design patterns that we have used in agricultural applications. In no way do we pretend to have covered entirely the subject of how to use design patterns in software development. For an advanced and full presentation of the design patterns, we strongly suggest the reader to consider the well-known book Design Patterns Elements of Reusable Object-Oriented Software [41].
Preface to the First Edition xi Our approach is based on the rational unified process (RUP) methodology, although it does not rigorously follow this methodology. Our focus is on presenting modeling issues during the analysis and design of agricultural systems. For a more detailed and advanced approach to RUP, the reader needs to consult more specialized books. What makes our book of unique value? Well, we have assembled in a comprehensive way a wide range of advanced software engineering techniques that will allow the reader to understand and apply these techniques in developing software applications in agriculture and related sciences. Agricultural systems tend to be more abstract than business systems. Everyone has a good understanding of how to use an ATM (automated teller machine). The use of an ATM is a classic example, used in many publications, to explain what an object is and how to build a UML diagram. The process of photosynthesis or the interaction of a plant with the surrounding environment, just to name a few typical agricultural examples, is less known to a large number of readers. Modeling a plant as an object provided with data and behavior may not be as straightforward as modeling an ATM. Therefore, the book aims to provide examples and solutions to modeling agricultural systems using the object-oriented paradigm and the UML. The book is intended to be of use to anyone who is involved in software development projects in agriculture: managers, team leaders, developers, and modelers of agricultural systems. Developing a successful software project in agriculture requires a multidisciplinary team: specialists from different fields with different scientific backgrounds. It is crucial to the success of the project that specialists involved in the project have a common language that everybody understands. We find that UML is an excellent tool for analyzing, designing, and documenting software projects. Models can be developed visually and using plain English (and any other language for that matter) and can be understood by programmers and non-programmers alike. Thus, collaboration between these groups is substantially improved by increasing the number of specialists directly involved in the process of software design and implementation. The book was written having always in mind the important number of specialists who still develop agricultural models using traditional approaches. There are ample step-by-step examples in this book that show how to depict concepts from a problem domain and represent them using objects and UML diagrams. We hope this book will be useful to these researchers and help them make a soft switch to the objectoriented paradigm. We hope readers will find this book of interest. Tirana, Albania Gainesville, FL, USA May 2006 Petraq J. Papajorgji Panos M. Pardalos
Contents Part I Concepts and Notations 1 Programming Paradigms... 3 1.1 History of Increasing the Level of Abstraction... 3 1.2 Object-Oriented Versus Other Programming Paradigms... 6 2 Basic Principles of the Object-Oriented Paradigm... 9 2.1 Abstraction... 9 2.2 Encapsulation... 12 2.3 Modularity... 12 3 Object-Oriented Concepts and Their UML Notation... 15 3.1 Object... 15 3.2 Classes... 16 3.3 Attributes... 17 3.4 Operations... 18 3.5 Polymorphism... 19 3.6 Interfaces... 20 3.7 Components... 24 3.8 Packages... 25 3.9 Systems and Subsystems... 26 3.10 Notes... 28 3.11 Stereotypes... 29 4 Relationships... 31 4.1 Associations... 31 4.2 Aggregation... 34 4.3 Composition... 35 4.4 Dependency... 36 4.5 Generalization... 37 4.6 Abstract Classes... 41 xiii
xiv Contents 4.7 Abstract Classes Versus Interfaces... 44 4.8 Realization... 45 5 Use Cases and Actors... 47 5.1 Actors... 47 5.2 Use Cases... 48 5.3 Extend Relationship... 50 5.4 Include Relationship... 51 6 UML Diagrams... 53 6.1 The Use Case Diagram... 53 6.2 Use Cases Versus Functional Decomposition... 55 6.3 Interaction Diagrams... 56 6.3.1 Need for Interaction... 56 6.3.2 Sequence Diagrams... 58 6.3.3 Collaboration Diagrams... 59 6.3.4 Sequence Versus Collaboration Diagrams... 61 6.4 Activity Diagrams... 61 6.5 Statechart Diagrams... 63 7 Design Patterns... 67 7.1 A Short History of Design Patterns... 67 7.2 Fundamental Design Patterns... 68 7.2.1 The Delegation Pattern... 68 7.3 Creational Patterns... 70 7.3.1 The Factory Method Pattern... 70 7.3.2 The Abstract Factory Pattern... 72 7.3.3 The Singleton Pattern... 74 7.4 Structural Patterns... 75 7.4.1 The Adaptor Pattern... 75 7.4.2 The Proxy Pattern... 78 7.4.3 The Iterator Pattern... 79 7.4.4 The Façade Pattern... 82 7.5 Behavioral Patterns... 84 7.5.1 The State Pattern... 84 7.5.2 The Strategy Pattern... 86 7.5.3 The Observer Pattern... 89 8 Exercises... 93 8.1 Exercise 1... 93 8.2 Questions... 98 8.3 Exercise 2... 99 8.4 Questions... 103 8.5 Exercise 3... 104 8.6 Questions... 110 8.7 Exercise 4... 112 8.8 Questions... 117
Contents xv 8.9 Exercise 5... 119 8.10 Questions... 119 9 The Object Constraint Language (OCL)... 121 9.1 Introduction... 121 9.2 The Design by Contract Approach... 122 9.2.1 Preconditions and Postconditions... 123 9.2.2 Invariants... 123 9.3 OCL Generalities... 123 9.3.1 The Self Keyword... 124 9.3.2 The Basic Types and Operators... 124 9.3.3 The String Type... 125 9.3.4 The Boolean Type... 125 9.3.5 The Integer and Real Types... 126 9.3.6 The Model Types... 127 9.4 Using OCL Within UML Models... 127 9.4.1 Using OCL to Navigate a UML Model... 129 9.4.2 More on Collections... 129 9.4.3 Examples of Invariants, Preconditions, and Postconditions... 130 9.5 OCL and Java... 133 10 The Model-Driven Architecture Approach... 135 10.1 Model-Driven Development... 135 10.2 MVC Pattern... 136 10.3 MDA Approach... 151 10.4 MDA and UML... 154 10.5 MDA Transformations... 155 10.5.1 PIM to Java Transformation... 156 10.5.2 PIM to Relational Transformation... 157 10.6 Modeling Behavior in MDA... 158 10.7 MDA with Virtual Enterprise... 162 10.7.1 Basic Concepts... 162 10.7.2 The Persistence Layer... 165 10.8 The Online Student System... 166 10.8.1 The Use Case Model... 166 10.8.2 The UML Model... 167 10.8.3 Providing Objects with Behavior in Virtual Enterprise... 171 10.8.4 Developing Portals in Virtual Enterprise... 176 Part II Applications 11 The Kraalingen Approach to Crop Simulation... 181 11.1 System Requirements... 182 11.2 The Use Case Model... 183 11.2.1 The Use Case Description... 184
xvi Contents 11.2.2 Basic Flow... 184 11.2.3 Alternate Flow... 185 11.2.4 Preconditions... 185 11.2.5 Postconditions... 185 11.3 The Use Case Realization... 186 11.3.1 Sequence Diagram for the Use Case... 186 11.3.2 Collaboration Diagram for the Use Case... 188 11.4 Conceptual Models... 190 11.4.1 Conceptual Model for the Kraalingen Approach... 191 11.5 Discover Potential Classes... 193 11.5.1 Boundary Classes... 193 11.5.2 Control Classes... 195 11.5.3 Entity Classes... 196 11.6 Class Diagram for the Kraalingen Approach... 197 11.7 Critique of the Kraalingen Class Diagram... 202 11.7.1 Communication Boundary Control... 202 11.7.2 Communication Control-Entity... 204 11.7.3 Communication Entity-Entity... 205 11.8 Final Class Diagram for the Kraalingen Approach... 208 11.9 The Benefits of Using Interfaces... 209 11.10 Implementation of the Kraalingen Model in Java... 209 11.10.1 Interface IPlant... 210 11.10.2 Interface ISoil... 212 11.10.3 Interface IWeather... 214 11.10.4 Class WeatherDataFromFile... 215 11.10.5 Class WeatherDataFromStation... 221 11.10.6 Interface ISimulator... 224 11.10.7 Packaging the Application... 227 12 The Plug and Play Architecture... 229 12.1 Definition... 229 12.2 Implementation... 230 12.3 Reflection... 231 12.4 The Plug and Play SimulationController... 232 12.5 Testing Unit for a Class/Component... 234 13 Soil Water-Balance and Irrigation-Scheduling Models: A Case Study... 239 13.1 Introduction... 239 13.2 Conceptual Models: Examples... 240 13.3 Template for Developing New Models... 242 13.4 Analysis of a Water-Balance Model... 244 13.5 Analysis of an Irrigation-Scheduling Model... 246 13.6 The Benefits of a General Template... 249
Contents xvii 14 Distributed Models... 251 14.1 Introduction... 251 14.2 Common Object Request Broker Architecture... 252 14.2.1 The Interface Definition Language... 253 14.2.2 The Object Request Broker... 254 14.2.3 Interface Adaptors... 256 14.2.4 A CORBA Soil Server... 256 14.2.5 A Simple CORBA Client... 260 14.3 The Remote Method Invocation... 261 14.3.1 An RMI Soil Server... 264 14.3.2 A Simple RMI Client... 266 14.4 Distributed Crop Simulation Model... 267 15 MDA with Oliva Nova... 273 15.1 The OO-Method... 273 15.2 Conceptual Model... 274 15.3 The MDA-Based Kraalingen Model... 275 15.4 Providing Objects with Behavior... 277 15.5 Debugging and Evaluating a Conceptual Diagram... 281 15.6 Code Generation... 283 16 Answers... 287 16.1 Answers to Exercise 1... 287 16.2 Answers to Exercise 2... 288 16.3 Answers to Exercise 3... 289 16.4 Answers to Exercise 4... 290 16.5 Answers to Exercise 5... 291 Glossary... 293 References... 297