--Your friends at LectureNotes

Note for Java Programming - JAVA By aravind nayak star

  • Java Programming - JAVA
  • Note
  • Uploaded 8 months ago
0 User(s)
Download PDFOrder Printed Copy

Share it with your friends

Leave your Comments

Text from page-1

PDHonline Course G195 (2 PDH) Object-Oriented Thinking Instructor: Warren T. Jones, Ph.D., PE 2012 PDH Online | PDH Center 5272 Meadow Estates Drive Fairfax, VA 22030-6658 Phone & Fax: 703-988-0088 www.PDHonline.org www.PDHcenter.com An Approved Continuing Education Provider

Text from page-2

www.PDHcenter.com PDH Course G195 www.PDHonline.org Object-Oriented Thinking Warren T. Jones, Ph.D. P.E. Course Content Module #1: Motivation for Object-Oriented (OO) Design The roots of object-oriented design reach back to the 1960’s to the Simula language developed at the Norwegian Computing Center. Simula is a simulation language and supports most of the basic concepts seen in OO languages today. The next significant development was the language Smalltalk, designed at Xerox Parc in the early 1970’s for use by non-professional programmers. The Department of Defense led the development of the Ada language in the late 1970’s and the Eiffel language was introduced in the mid 1980’s. C++ appeared on the scene in the early 1980’s and was the first OO language to go mainstream. Then in the mid nineties Java began to dominate the OO landscape, driven by the emergence of the Web and the demand for distributed applications in general. Microsoft’s C# and the open source Ruby on Rails are recent developments. A language called Alice is now also available based on an interface and objects that resemble a game-playing environment that makes learning OO more visually appealing and intuitive. So why should engineers be interested in OO technology? It is true that OO is more complex and the transition from languages like C to OO is known to be more challenging than just learning another procedure-oriented language. Making the jump to an OO language like Java may be motivated by requirements for platform independence or networking. Another rationale for considering OO can be given in two words that are very easy for engineers to understand, cost and reliability. The dream from the outset of the OO concept was that the creation of software could become a process of construction from collections of standard components in a library in much the same way as now is commonplace in electrical or civil engineering. Later in this course the mechanisms that have been developed to help move this dream toward reality are described. During the past several decades the software development process (See PDHOnline course in Software Engineering Concepts) has been studied with the goal of coming up with improvements in the process that will solve the so-called “software crisis” of increasing costs and reliability problems as software systems have increased in complexity. Early attempts, such as structured programming of procedure-oriented code, focused on improving the latter stages of the process, such as the production of modular code. More recently the OO approach has sought to produce improvements on the early stages of the software development process. Another way of saying this is that structured programming addresses issues in the solution set (code implementation) near the end, Page 1 of 9

Text from page-3

www.PDHcenter.com PDH Course G195 www.PDHonline.org whereas OO design and programming seeks to improve the approach to the problem set (requirements and architectural design) at the beginning [1]. Often cited strengths of the OO approach are: • • • • • • OO descriptions can be understood by individuals with little technical background in programming thus reducing the communication problem with clients. OO programming languages support and promote code reuse which, in turn, increases programmer productivity and can lead to reduced development and testing costs. OO designed systems are easier to change. OO design can be viewed as a real-world modeling technique in much the same manner as a computer simulation model. OO design methodology scales well from simple to very complex systems. OO facilitates rapid development by focusing on the early stages of the development process. Module #2: OO Foundations The term “A new programming paradigm” is often used when referring to OO programming. The use of the term “paradigm” here is taken from its use in the book Structure of Scientific Revolutions by the historian of science Thomas Kuhn. He used “paradigm” to refer to the way science organizes knowledge into theories and methods that represent a way of viewing the world. This view of the world may change when new paradigms emerge that replace the older views. A programming paradigm is an approach to conceptualizing what it means to carry out a computational process and how computational tasks should be organized. The OO paradigm is very close to how we think of problem solving in our everyday lives. We use a familiar situation to illustrate some basic principles of OO. Consider the scenario of ordering a pizza for home delivery. Suppose a person named Jim decides he wants pizza for dinner. He has a certain type of pizza in mind and the specific toppings he likes. Suppose further that he doesn’t want to prepare and cook the pizza himself. He would like to delegate this responsibility to someone else who has the skills to do this. So Jim makes a telephone call to the local pizza parlor and passes the owner, Alan, the information about the pizza he desires and his home address with the full confidence that Alan will take responsibility to accomplish the task requested. When the pizza is ready, Alan passes it to Walter, the delivery person, who then makes the delivery to the correct address. Notice that the above problem of obtaining a pizza for dinner was solved by finding an appropriate agent Alan and passing a message to him containing the request. Alan then has the responsibility to carry out the request. Also notice that there is a set of operations or methods that Alan will use to appropriately prepare the pizza. These preparation and Page 2 of 9

Text from page-4

www.PDHcenter.com PDH Course G195 www.PDHonline.org cooking details, that Jim need not know, are “hidden” from him. Similarly, when Alan gives the pizza to Walter with the message to deliver, Alan need not know all the details of how to get the delivery accomplished. These are hidden from him. He has delegated this task to Walter and Walter has the method for carrying out the delivery. This scenario illustrates several aspects of OO: • An object-oriented program can be viewed as a set of agents called objects which interact by appropriate message passing. Each object provides a service that is used by other objects. In the above illustration, Jim the requestor, Alan the cook and Walter the delivery person, represent agents in the pizza delivery process. Notice that the problem of getting the requested pizza to Jim is solved by passing messages from a requesting agent to a receiving agent in two stages. The message is sent first from Jim to Alan the cook and then from Alan to Walter the delivery person. In each case the request was given to the receiving agent with the responsibility to carry out the request with the methods available to him. The methods used are of no concern to the requestor and are hidden from him. More than one method may be available to an agent. For example, Walter could choose to use an SUV or a sedan for delivery. He could consult a city map in the pizza parlor or he could use a GPS navigation system in his vehicle. • The concept of information hiding, frequently called encapsulation is an important aspect of OO programs. When Jim envisioned ordering a pizza, he had knowledge of pizza parlors in general. That is, he knew what type of products they sold and how they operated. In other words, pizza parlors are a class of restaurants and the particular one he called at some address, for example 56 Main Street, was an instance of this class. • All objects are instances of some class. The methods used by an object are defined in the class associated with that object. Elements encapsulated inside a class are not accessible to code outside the class. We sometimes say that classes have a public interface for message communication and a private hidden implementation for method details and attributes. Classes are also referred to as blueprints for objects. Moreover, classes can be organized into class hierarchies of more general knowledge. For example, one could think of moving up a class hierarchy of pizza parlor, restaurant, retail store, etc. in which each is a subclass of the next one in the list. • Class hierarchies can be constructed in which a subclass inherits attributes from the class above it. In the OO world view, programming does not begin with variables, assignments or addresses. Instead, the language and framework is that of objects, messages and Page 3 of 9

Lecture Notes