You are on page 1of 42

D.

S Giri LipNi Services


http://SliceData.BlogSpot.com dharmendra.giri@gmail.com

` ` ` ` ` ` ` ` ` ` ` `

OO Programming What? / Why? and Benefit Real World Objects Data Abstraction Class / Objects Aggregation Association Encapsulation Inheritance Polymorphism Interface / Events / Listeners UML Notations Modeling Tools - Rational Rose Concepts
LipNi Services 2

` `

An approach to application development Appropriate for large-scale applications with teams of developers

OO programming paradigm: collection of objects

LipNi Services

The Evolution of OOPS


` ` ` ` ` ` `

Global Variables -lifetime spans program execution. Local Variables - lifetime limited to execution of a single routine. Nested Scopes - allow functions to be local. Static Variables - visible in single scope. Modules - allow several subroutines to share a set of static variables. Module Types - multiple instances of an abstraction. Classes - families of related abstractions.
LipNi Services 4

` `

Reduces conceptual load by reducing amount of detail Provides fault containment


Cant use components (e.g., a class) in inappropriate ways

Provides independence between components


Design/development can be done by more than one person

LipNi Services

Keys to OO Programming
` `

An instance of a class is know as an Object. Languages that are based on classes are know as Object-Oriented.
Eiffel C++ Modula-3 Ada 95 Java SmallTalk Microsoft .NET Languages - C# and VC++ etc
The concept of objects and object-oriented programming exist in dozens of computer languages. The object model is implemented with sometimes slight and sometimes substantial differences in each of these languages.

LipNi Services

` ` `

Promotes code reuse Reduces code maintenance Simplifies extending applications

LipNi Services

Object-orientation is so called because this method sees things that are part of the real world as objects. ` Phone ` Bicycle ` Human Being ` Insurance policy are objects. In everyday life, we simplify objects in our thinking we work with models. Software development does essentially the same: objects occurring in reality are reduced to a few features that are relevant in the current situation.
`

LipNi Services

Complex realities are made more manageable by abstract models.

LipNi Services

Abstraction is the presentation of simple concept (or object) to the external world. Abstraction concept is to describe a set of similar concrete entities. It focuses on the essential, inherent aspects of an entity and ignoring its accidental properties. The abstraction concept is usually used during analysis: deciding only with application-domain concepts, not making design and implementation decisions.
LipNi Services 10

Two popular abstractions: Procedure abstraction - This is to decompose problem to many simple sub-works. Data abstraction- This is to collect essential elements composing to a compound data.

These two abstractions have the same objective: reusable and replaceable.

LipNi Services

11

Example of Data Abstraction.

LipNi Services

12

Encapsulation means as much as shielding. Each objectoriented object has a shield around it. Objects can't 'see' each other. They can exchange things though, as if they are interconnected through a hatch It separates the external aspects of an object from the internal implementation details of the object, which are hidden from other objects. The object encapsulates both data and the logical procedures required to manipulate the data.

LipNi Services

13

LipNi Services

14

A class is used to describe something in the world, such as occurrences, things, external entities, roles, organization units, places or structures. A class describes the structure and behavior of a set of similar objects. It is often described as a template, generalized description, pattern or blueprint for an object, as opposed to the actual object, itself.

LipNi Services

15

Once a class of items is defined, a specific instance of the class can be defined. An instance is also called object.

Class and Object.


The table gives some examples of classes and objects

Type Occurrence Things External entities Roles Organization al units

Example of class Alarm Car Door Teacher IECS department

Example of object Fire alarm Ferrari 360 Fire door John, Nick FCU_IECS,

LipNi Services

16

Properties in a class are used to present the structure of the objects: their components and the information or data contained therein. (e.g., name, owner, ground clearance).An instance of a class has the properties defined in its class and all of the classes from which its class inherits. Methods in a class describe the behavior of the objects. It represents a function that an instance of the class can be asked to perform.

An example of a Dog Class

LipNi Services

17

Each instance contains the same properties and handlers as the class, but the properties values of each instance are encapsulated. You may change them without affecting the other instances or the class script.

LipNi Services

18

An object is a discrete entity. In object-oriented programming, an object is the product or instance generated by a class. An object can have properties, exhibit behaviors, execute methods, and calculate and return values.

Reusability and encapsulation are the two most obvious benefits of object-oriented programming paradigms. You can use a single class script to create an unlimited number of specialized instance objects, and each of those objects is a protected, encapsulated instance. In other words, the instances dont affect or alter the class; they don't affect or alter one another.

LipNi Services

19

A composition object is an object based on a physical thing, like this refrigerator.

LipNi Services

20

The refrigerator object is not empty. It has a series of shelves inside and each one contains other objects. The top shelf, for example, has a milk carton in it. So just to recap, the refrigerator has a milk carton. The milk carton, in turn, has a quantity of milk inside it

The "has-a" relationship between various objects in composition objects is similar to spatial relationships in everyday things.

LipNi Services

21

These objects are generally used to model conceptual relationships rather than spatial ones.
Lots of things exist only as conceptual or classification concepts and have no actual physical form. These are the sorts of things that fit well in this type of object structure.

LipNi Services

22

What sort of fruit is a fruit? Can you ask for fruit at breakfast and be certain of the result? Only in the sense that youll probably be given some sort of fruit, but you have no idea whether to expect strawberries or bananas. Yet there is a substantial difference between strawberries and bananas. A strawberry is a fruit. A banana is a fruit, as is a kiwi. Because of this conceptual (is a type) relationship between objects, these objects inherit certain common qualities from their original classification. Fruit are all plants, and all are sweet, and all have seeds (barring genetic manipulation). This group gets their name, "inheritance object," from this relationship. The reason that they are all able to descend from one class is because we are able to conceptually link these things together. Their common origin exists in our heads.

LipNi Services

23

An association is a relationship between different objects of one more classes.

A simple example of an association is the relationship among an enterprise, departments and employees

LipNi Services

24

In the simple case, an association is represented by a single line between two classes. Usually, however, associations are shown in as much detail as possible. Then, the association receives a name and a numerical specification (Multiplicity indication) of how many objects on one side of the association are connected with how many objects on the other side. Example of association with multiplicity. Common multiplicities are:

0..1 1 0..*, * 1..*

No instance, or one instance Exactly one instance Zero or more instances One or more instances

LipNi Services

25

Aggregation is a special form of association. Aggregation is the composition of an object out of a set of parts. A car, for example, is an aggregation of tires, engine, steering wheel, brakes and so on. These parts may in turn be aggregations: a brake consists of disk, pads, hydraulic, etc. Aggregation represents a has relationship: a car has an engine. Instead of aggregation, some people talk about whole-part hierarchy.

Enterprise represents a whole end and Department represents a part end.

LipNi Services

26

Inheritance is the property whereby one class extends another class by including additional methods and/or variables. The original class is called the superclass of the extending class, and the extending class is called the subclass of the class that is extended. Since a subclass contains all of the data and methods of the superclass plus additional resources, it is more specific. Conversely, since the superclass lacks some of the resources of the subclass, it is more general or abstract, than its subclasses

LipNi Services

27

Example, where Circle and Rectangle inherit from GeomFigure and own all attributes and methods from GeomFigure.

LipNi Services

28

Interface classes are abstract definitions of purely functional interfaces. They DO NOT define any attributes or associations. An interface can not instantiate any object instances. They only define a set of abstract operations. They often define pre-conditions, post-conditions, invariants and possible exceptions for these operations.

Example the String class implements the interface Sortable. Note that isEqual() in the interface Sortable do not have method implemented, but String must have its implementation on isEqual() since it is defined to implement Sortable.

LipNi Services

29

An event listener is an object to which a component has delegated the task of handling a particular kind of event. In other words, if you want an object in your program to respond to another object which is generating events, you must register your object with the event generating object, and then handle the generated events when the come.

LipNi Services

30

JButton is a kind of event source component. When the event is activated, it will notify ActionListener to handle it. The EventHandler is a ActionListener responsible for the event.

LipNi Services

31

Communication between objects is achieved by exchanging messages

These messages lead to the operations, which means that an object understands precisely those messages for which it has operations.

Message Exchange in Classes

LipNi Services

32

Polymorphism indicates the meaning of many form. In object-oriented design, polymorphism present a method can has many definitions (forms). Polymorphism is related to

Overloading Overriding.
Overloading indicates a method can have different definitions by defining different type of parameter, for example getPrice(): void getprice(String name): void getPrice() has two different forms is the same meaning of different definitions.

LipNi Services

33

Overriding indicates that subclass and parentclass have the same methods, parameters and return types (namely to redefine the methods in parentclass).

LipNi Services

34

encrypt(String) method has three definitions, distribute in subclass and parentclass. Document object claims Encryption object to assist ecryption. In its encryString() method, it doesnt indicate RSAEncryption or DesEncryption is the encryption actor, just only send a message to Encryption object:

EncryptString(Encryption e) { result = e.encrypt(source); }

LipNi Services

35

The Unified Modeling Language was originally developed at Rational Software but is now administered by the Object Management Group. It is a modeling syntax aimed primarily at creating models of software-based systems, but can be used in a number of areas. It is:

LipNi Services

36

Syntax only - UML is just a language, it tells you what model elements and diagrams are available and the rules associated with them. It doesn't tell you what diagrams to create. Comprehensive - it can be used to model anything. It is designed to be user extended to fill any modeling requirement. Language independent - it doesn't matter what hi-level language is to be used in the code. Mapping into code is a matter for the case tool you use. Process independent - the process by which the models are created is separate from the definition of the language. You will need a process in addition to the use of UML itself. Well documented - the UML notation guide is available as a reference to all the syntax available in the language.

LipNi Services

37

Notation Class

Name

Description A class describes the structure and behavior of a set of similar objects. An instance of a class A relationship between different objects of one more classes One class extends another class Abstract definitions of purely functional interfaces Implement the functions defined in interface

Object Association

Inheritance Interface Interface Implementation

LipNi Services

38

Aggregation Others refer to UML Spec.

Aggregation is the composition of an object out of a set of parts.

LipNi Services

39

Rational Rose
Except the Ration Rose, there are still many other UML modeling tools, such as:1. ArgoUML 2. Borland Together 3. Rational XDE 4. Eclipse 5. Power Designer 6. Visual Paradigm 7. MagicDraw etc.

LipNi Services

40

Rational Rose is a program that allows you to build models based on the Unified Modeling Language or more commonly known as the UML. You are able to create three diagrams in Rational Rose:1. Use-case diagram 2. Sequence diagram 3. Class diagram.

LipNi Services

41

` Question

? at

` You can reach me dharmendra.giri@gmail.com ` Or Visit my BLOG


`

http://SliceData.BlogSpot.com

LipNi Services

42

You might also like