Oracle DBA Forum  

Вернуться   Oracle DBA Forum > Oracle University Official Study Notes (ENG) > Oracle 10g Java Programming > Oracle 10g Java Programming

Ответ
 
Опции темы Опции просмотра
  #1  
Старый 14.01.2010, 01:06
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,385
По умолчанию 02 Defining Object-Oriented Principles

__________________
Чат форума (требуется аккаунт на github или twitter)
Ответить с цитированием
  #2  
Старый 14.01.2010, 01:06
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,385
По умолчанию Objectives



Lesson Aim

This lesson introduces the concepts of classes and objects, which are the foundation to the object-oriented approach to building applications. It explains the benefits and implementation of object-oriented principles. It introduces Classes, Objects, and Methods and contrasts OO principles with traditional programming techniques. This lesson defines the terms Abstraction, Encapsulation, Inheritance, and Polymorphism, and explains the benefits of each of these principles. The course application class structure is presented and a simple use case scenario is discussed to provide context for using an object defined by the class model.

Overview of Object-Oriented Programming

Object-oriented programming (OOP) is a relatively new paradigm for creating computer programs that are adaptable, reusable, and can stand the test of time. The functionality comes from the design of discrete classes that contain information about objects as well as expected behaviors. In an OO program, objects send messages to one another and expect certain behaviors or messages in return.

A good example of object orientation is the personal computer (PC). Although this is not a programming example, it serves as an example of what OOP can deliver in a programming environment.

Each PC is made up of components that are manufactured by several unrelated companies. Each component is built to a specification that includes information and behaviors. A CD drive, for example, is expected to return data from a CD when the operating system asks for it. The PC manufacturer does not need to be concerned with the internal workings of the CD drive, only that it responds to requests appropriately.

In the same way, an OO program may make calls to objects without knowing all the details of the objects. The program simply expects to get information or produce a specific behavior. By defining each of these objects separately, the internal workings of each object can change as long as the way they are called and how they behave stay the same.

OOP uses a number of techniques to achieve adaptability including abstraction, encapsulation, inheritance, and polymorphism. Each of these topics is discussed in the next few pages.
__________________
Чат форума (требуется аккаунт на github или twitter)

Последний раз редактировалось Marley; 04.03.2010 в 09:25.
Ответить с цитированием
  #3  
Старый 14.01.2010, 01:06
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,385
По умолчанию What Is Modeling?



The House-Building Metaphor

Imagine someone who wants to have a house built. Initially, the house exists only in the minds of the future home owners as ideas, or pieces of various dreams. Sometimes, the future inhabitants may not even know what they want, or know whether what they want is even feasible. Dreams may be full of internal contradictions and impossibilities. This is not a problem in the dream world; in the physical realm, any inconsistencies and obstacles must be resolved before someone can construct the house.

A building contractor needs a solid set of blueprints of the house with a description of the materials to be used, the size of the roof beams, the capacity of the plumbing, and so on. The contractor follows the plan, and has the knowledge to construct what is on the blueprint. But how do the ideas of the home owner become the blueprint for the contractor? This is where the architect comes in.

The architect is the intermediary between the sponsor and the contractor. He or she is trained in the skills of translating ideas into models. The architects skills in extracting ideas, putting them down in a format that enables discussion and analysis, giving advice, describing sensible options, documenting them, and confirming them with the home owners, are the cornerstones to providing the future home owners with a plan of the home they want.
__________________
Чат форума (требуется аккаунт на github или twitter)

Последний раз редактировалось Marley; 04.03.2010 в 09:26.
Ответить с цитированием
  #4  
Старый 14.01.2010, 01:07
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,385
По умолчанию What Are Classes and Objects?



What Is an Object?

An object is something tangible, something that can be seen or touched, or something that can be alluded to and thought about.
Object-oriented programs consist of several objects. These objects communicate with each other by sending messages from one object to another. In a true object-oriented program, that is all you have: a coherent group of communicating objects. New objects are created when needed, old ones are deleted, and existing objects carry out operations by sending messages.

Some examples of objects in an OO program are Customer, Invoice, RentalAgreement, Video, and so on. Each of these objects holds information about itself and performs certain behaviors. A customer has a name, address, and phone number. A customer may also rent a video, return a video, pay a bill, and have other behaviors.

What Are Classes?

A class is a model of abstraction from real-world objects. A class defines the properties and behavior of a set of objects. A class denotes a category of objects and acts as a blueprint for creating that type of object.
__________________
Чат форума (требуется аккаунт на github или twitter)

Последний раз редактировалось Marley; 04.03.2010 в 09:28.
Ответить с цитированием
  #5  
Старый 14.01.2010, 01:07
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,385
По умолчанию An Objects Attributes Maintain Its State



An Objects Attributes Maintain Its State

All the data that an OO system requires must be located in attributes of the existing objects. Some objects have little or no data, whereas other objects have a lot of data; it depends entirely on the operations that the object is to perform.

The collection attributes that are defined in an object determine its internal structure; in essence, the object is a composite data structure, which is often called a user-defined type.

The values that are held in the attributes, at a given point in time, represent the current state of the object. As the values of attributes change, over time, the state of the object changes. The state of an object is remembered as long as the object exists in the system (memory). The attribute values are typically altered by executing an object method in response to some internal or external event. It is the job of the object code to maintain the integrity of the objects state; that is, to ensure that the object state is valid for that object.

Typical Attributes

As with operations, different objects store different attributes. For example, the Acme Bank ATM object has attributes such as cash available, cards recognized, ATM code, and so on. The blue pen object has attributes such as amount of ink remaining, diameter of nib, length of stem, and so on.

Attributes are often deduced after you have decided what operations the object will supply. After you know what the object must do, you are much better positioned to decide what attributes the object must store to support these operations. Often, the attributes of an object are initially known and can be used to define the type of operations that are required to maintain their value.
__________________
Чат форума (требуется аккаунт на github или twitter)

Последний раз редактировалось Marley; 04.03.2010 в 09:30.
Ответить с цитированием
  #6  
Старый 14.01.2010, 01:07
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,385
По умолчанию Objects Have Behavior



Objects Have Behavior

The major purpose that is served by objects is performing operations in the system in which they exist. Object technology decomposes a system entirely into objects; all the interactions between the system and the outside world, and all the internal computations of the system, are carried out by the operations (or methods) of objects.

Typical Operations

Different objects naturally perform different operations. For example, the Acme Bank ATM object has operations such as withdraw, print receipt, swipe card, and so on. Alternatively, the my blue pen object has operations such as write, leak ink, and so on.

For each object, you have to ask yourself: What does this object do for me? In other words, what services does this object supply for the other objects in the system? To do this, you must have an idea about how the object will be used in the system; otherwise, you may end up defining several operations for each object, which is clearly unsatisfactory. It is important to understand how the object will be used in the system and to specify only the operations that are relevant for that mode of usage.

You must also ask how the state of the object is changed; that is, How do the values that are held in the object attribute get modified? This question enables you to define operations to maintain the internal details of an object.
__________________
Чат форума (требуется аккаунт на github или twitter)

Последний раз редактировалось Marley; 04.03.2010 в 09:31.
Ответить с цитированием
  #7  
Старый 14.01.2010, 01:07
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,385
По умолчанию Objects Are Modeled as Abstractions



Objects Are Modeled as Abstractions

How do you decide what operations and attributes are relevant to the model of the my blue pen object? The answer is simple. You must understand how the object will be used by the other objects in the context of this particular system. You model the object as an abstraction of the real-world example in the context in which it exists.

For example, in the context of a product catalog, the relevant attributes of a pen are reported, such as the model or name, price, and the manufacturer (for example, Mont Blanc). The operations that are relevant to this catalog would be to change the price of this pen.

You may need to know whether the pen can be used to write text, be refilled, or have its ink color changed by replacing a cartridge. However, these latter operations are more relevant to the way the pen is used by the customer who is purchasing the pen, and therefore the refill, write, change ink operations are not relevant to the catalog application context and must not be modeled. When deciding on the attributes and operations for an object, always ask whether they have relevance in the domain of the application; always evaluate the attributes and operations in the application context; that is, Are they required to successfully implement the system to meet business requirements?


Every Object Is Unique

By definition, each object instance has a unique identity; even if two or more objects have identical states, that is, if their attribute values are the same, the system always treats them as different objects. When you create objects in software, you are given a handle to the object, called an object reference in the Java language. In Java, this handle or object reference is given a name by which it can refer to the object.
__________________
Чат форума (требуется аккаунт на github или twitter)

Последний раз редактировалось Marley; 04.03.2010 в 09:33.
Ответить с цитированием
  #8  
Старый 14.01.2010, 01:07
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,385
По умолчанию Defining Object Composition



Defining Object Composition

For example, when you talk about writing or reading from a CD drive, you consider the CD drive as a single object. You may also discuss how the CD drive interacts with the personal computer system; you treat the computer systems as a single object as well.

When an engineer is called in to repair a CD drive problem, his or her perspective of a CD drive is more detailed. The engineer visualizes the CD drive spindle, the drive tray, and the laser beam or reader.

Each of these are components of the CD drive object, and are objects in their own right. Each of these views of the CD drive is equally valid, and each can be expressed at different times.

When discussing objects, it is useful to use as high a level of abstraction as possible. In this way, you can conceptualize more of the important objects, and understand more about how the system works.


Aggregation

This concept of objects being composed of many subobjects is known as aggregation.
When you break a big object down into several low-level objects, these low-level objects can often be reused in subsequent projects. For example, ATMs use keypads, but so do cash registers, telephones, and television remote controls.

Note: An aggregation is a special type (closely coupled) of association known as a composition. To make a distinction, think of an association as a collaborates with relationship. Think of an aggregation as a made of or composed of relationshipfor example, an account is made of transactions, whereas an order is made of order lines. There are two types of aggregation, strong and weak. Strong aggregation is also called composition. Both are implemented by using references in Java.
__________________
Чат форума (требуется аккаунт на github или twitter)

Последний раз редактировалось Marley; 04.03.2010 в 09:35.
Ответить с цитированием
  #9  
Старый 14.01.2010, 01:08
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,385
По умолчанию The Donut Diagram



The Donut Diagram

The donut diagram provides a visible reminder that an object presents an external interface in the form of methods and that its instance variables (in this case, name, address, and birthdate) are private and hidden inside.

Client objects interact with this Person object by sending messages to it; that is, by invoking its public methods. The client does not know how the getAge method works, nor should the client care. There could be an age variable in the place of the calculation based on the birthdate variable. Or perhaps this kind of object returns a constant 39.

Note: This style of diagram has been a very popular one that is useful for conveying concepts. However, for real-world projects, it quickly becomes limiting: Real objects could have many methods, which would not fit very well. A similar diagram, which is part of Unified Modeling Language (UML), is known as an interaction diagram. An interaction diagram is a generic term that applies to several types of diagrams, such as collaboration diagrams, activity diagrams, and sequence diagrams. They all represent in different ways where objects are drawn simply as circles, and messages among them are drawn as arrows.

Oracle University provides an inClass course on UML techniques and notation named Object-Oriented Analysis and Design using the Unified Modeling Language (UML).

For further information, refer to http://education.oracle.com.
__________________
Чат форума (требуется аккаунт на github или twitter)

Последний раз редактировалось Marley; 04.03.2010 в 09:38.
Ответить с цитированием
  #10  
Старый 14.01.2010, 01:08
Marley Marley вне форума
Senior Member
 
Регистрация: 19.09.2009
Сообщений: 7,385
По умолчанию Guided Practice: Spot the Operations and Attributes



Spot the Operations and Attributes

For each graphic, specify at least three attributes and three operations.
__________________
Чат форума (требуется аккаунт на github или twitter)

Последний раз редактировалось Marley; 04.03.2010 в 09:39.
Ответить с цитированием
Ответ
Опции темы
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.

Быстрый переход


Текущее время: 16:56. Часовой пояс GMT +3.


Powered by vBulletin®