oop concepts

29
OOP Concepts OOP Concepts Copyright: Copyright: Beta Soft Systems Beta Soft Systems

Upload: ritu-mangla

Post on 08-May-2015

2.387 views

Category:

Technology


1 download

DESCRIPTION

Object Oriented concepts

TRANSCRIPT

Page 1: Oop concepts

OOP ConceptsOOP Concepts

Copyright:Copyright:

Beta Soft Systems Beta Soft Systems

Page 2: Oop concepts

AbstractionAbstraction

AbstractionAbstraction refers to the act of refers to the act of representing essential features representing essential features without including the background without including the background details or explanations. details or explanations.

Page 3: Oop concepts

PolymorphismPolymorphism

Polymorphism refers to the process Polymorphism refers to the process whereby an object invokes a method whereby an object invokes a method of another object in a common of another object in a common manner (with the same name) manner (with the same name) without understanding or caring how without understanding or caring how it is accomplished it is accomplished

Page 4: Oop concepts

InheritanceInheritance

It is a way to form new or derived It is a way to form new or derived classes using classes or base classes classes using classes or base classes that have already been defined. It is that have already been defined. It is also known as generalization. Models also known as generalization. Models Is-A relationship.Is-A relationship.

Multiple inheritance may lead to the Multiple inheritance may lead to the Black Diamond Problem.Black Diamond Problem.

Page 5: Oop concepts

Aggregation and Aggregation and CompositionComposition

Association refers to ability to send Association refers to ability to send message between object instancesmessage between object instances

Aggregation is the typical whole/part Aggregation is the typical whole/part relationship relationship

Composition is similar to Composition is similar to Aggregation, except lifetime of the Aggregation, except lifetime of the part is controlled by wholepart is controlled by whole

Page 6: Oop concepts

EncapsulationEncapsulation

Encapsulation refers to hiding Encapsulation refers to hiding implementation details such as implementation details such as object’s behaviors and attributesobject’s behaviors and attributes

It is also known as Separation of It is also known as Separation of Concerns or Information HidingConcerns or Information Hiding

It reduces risk by shifting code’s It reduces risk by shifting code’s dependency on well defined dependency on well defined interfacesinterfaces

Page 7: Oop concepts

ModularityModularity

Modularity is closely tied with Modularity is closely tied with encapsulation; think of modularity as encapsulation; think of modularity as a way of mapping encapsulated a way of mapping encapsulated abstractions into real, physical abstractions into real, physical modulesmodules

It allows breaking up of something It allows breaking up of something complex into manageable piecescomplex into manageable pieces

Page 8: Oop concepts

AssociationAssociation

An association represents an object An association represents an object of one class making use of an object of one class making use of an object of another classof another class

Page 9: Oop concepts

CouplingCoupling

Coupling describes how dependent one object is on another Coupling describes how dependent one object is on another object (that it uses)object (that it uses)

Coupling is a measure of the strength of the connection Coupling is a measure of the strength of the connection between any two system components. The more any one between any two system components. The more any one component knows about another component, the tighter component knows about another component, the tighter (worse) the coupling is between those two components. (worse) the coupling is between those two components.

Coupling types areCoupling types are Field levelField level Method levelMethod level Constructor levelConstructor level API levelAPI level Message levelMessage level Protocol levelProtocol level

Page 10: Oop concepts

CohesionCohesion

Cohesion defines how narrowly defined an object is. Functional Cohesion defines how narrowly defined an object is. Functional cohesion refers measures how strongly objects are relatedcohesion refers measures how strongly objects are related

Cohesion is a measure of how logically related the parts of an Cohesion is a measure of how logically related the parts of an individual component are to each other, and to the overall individual component are to each other, and to the overall component. The more logically related the parts of a component. The more logically related the parts of a component are to each other the higher (better) the cohesion component are to each other the higher (better) the cohesion of that component. of that component.

Low coupling and Tight cohesion is good object oriented Low coupling and Tight cohesion is good object oriented design (OOD)design (OOD)

Page 11: Oop concepts

Design PrinciplesDesign Principles

GRASP – General Responsibility Assignment Software GRASP – General Responsibility Assignment Software PatternsPatterns

REP – Release / reuse equivalency principle REP – Release / reuse equivalency principle OCP – Open closed principleOCP – Open closed principle CQP - Command query separation principleCQP - Command query separation principle ISP - Interface segregation principleISP - Interface segregation principle DIP - Dependency inversion principleDIP - Dependency inversion principle LSP – Liskov’s substitution principleLSP – Liskov’s substitution principle CCP – Common closure principleCCP – Common closure principle ADP - Acyclic dependencies principleADP - Acyclic dependencies principle SDP - Stable dependencies principleSDP - Stable dependencies principle SAP - Stable abstractions principleSAP - Stable abstractions principle LoD - Law of DemeterLoD - Law of Demeter

Page 12: Oop concepts

GRASP (General Responsibility GRASP (General Responsibility Assignment Software patterns)Assignment Software patterns)

Information ExpertInformation Expert CreatorCreator High CohesionHigh Cohesion Low CouplingLow Coupling ControllerController PolymorphismPolymorphism IndirectionIndirection Pure FabricationPure Fabrication Protected VariationProtected Variation

Page 13: Oop concepts

Release/Reuse equivalency Release/Reuse equivalency principle (REP)principle (REP)

The granule of reuse is the granule of The granule of reuse is the granule of release. Only components that are release. Only components that are released through a tracking system released through a tracking system can be effectively reused. This can be effectively reused. This granule is the packagegranule is the package

Page 14: Oop concepts

Open closed principle (OCP)Open closed principle (OCP)

Software entities like classes, Software entities like classes, modules and functions should be modules and functions should be open for extension but closed for open for extension but closed for modificationsmodifications

Page 15: Oop concepts

Command Query separation Command Query separation principleprinciple

Every method should either be a Every method should either be a command that performs an action, or command that performs an action, or a query that returns data to the a query that returns data to the caller, but not bothcaller, but not both

Page 16: Oop concepts

Interface Segregation Principle Interface Segregation Principle (ISP)(ISP)

Clients should not be forced to Clients should not be forced to depend on methods that they do not depend on methods that they do not useuse

Page 17: Oop concepts

Dependency inversion principle Dependency inversion principle (DIP)(DIP)

High level modules should not High level modules should not depend upon low level modules. Both depend upon low level modules. Both should depend upon abstractions. should depend upon abstractions. Abstractions should not depend upon Abstractions should not depend upon details. Details should depend upon details. Details should depend upon abstractionsabstractions

Page 18: Oop concepts

Liskov’s Substitution Principle Liskov’s Substitution Principle (LSP)(LSP)

In class hierarchies, it should be In class hierarchies, it should be possible to treat a specialized object possible to treat a specialized object as if it were a base class objectas if it were a base class object

Page 19: Oop concepts

Common Closure Principle Common Closure Principle (CCP)(CCP)

Classes that change together, belong Classes that change together, belong together together

Page 20: Oop concepts

Common Reuse PrincipleCommon Reuse Principle

Classes that aren't reused together Classes that aren't reused together should not be grouped together should not be grouped together

Page 21: Oop concepts

Acyclic Dependencies Acyclic Dependencies PrinciplePrinciple

The dependency structure for The dependency structure for released components must be a released components must be a directed acyclic graph. There can be directed acyclic graph. There can be no cyclesno cycles

Page 22: Oop concepts

Stable Dependencies Stable Dependencies principleprinciple

Dependencies between released Dependencies between released categories must run in the direction categories must run in the direction of stability. The dependee must be of stability. The dependee must be more stable than the dependermore stable than the depender

Page 23: Oop concepts

Stable Abstractions PrincipleStable Abstractions Principle

The more stable a class category is, The more stable a class category is, the more it must consist of abstract the more it must consist of abstract classes. A completely stable category classes. A completely stable category should consist of nothing but should consist of nothing but abstract classesabstract classes

Page 24: Oop concepts

Law of DemeterLaw of Demeter

An object should avoid invoking An object should avoid invoking methods of a member object methods of a member object returned by another method returned by another method

It is also known as Principle of Least It is also known as Principle of Least KnowledgeKnowledge

Page 25: Oop concepts

Design best practicesDesign best practices

Pick nouns or noun phrases as classesPick nouns or noun phrases as classes Method names should contain a verbMethod names should contain a verb Delegate to helper classDelegate to helper class Use declarative configuration, don’t Use declarative configuration, don’t

hardcodehardcode Modular designModular design Divide code into framework and Divide code into framework and

abstractionabstraction

Page 26: Oop concepts

Analysis & Design Analysis & Design approachesapproaches

1.1. Nouns and noun sentence analysis : Identify Nouns and noun sentence analysis : Identify the nouns and verbs in Use Cases. Nouns the nouns and verbs in Use Cases. Nouns are classes and verbs are methodsare classes and verbs are methods

2. Domain analysis : Identify objects using : Identify objects using business domain knowledgebusiness domain knowledge

3. CRC (Class Responsibility Collaborator) : (Class Responsibility Collaborator) : This technique uses cards to identify objectsThis technique uses cards to identify objects

4. Robustness analysis : Identify the control, : Identify the control, entity and boundary objectsentity and boundary objects

Page 27: Oop concepts

Design tradeoffsDesign tradeoffs

Flexibility vs. SimplicityFlexibility vs. Simplicity Dynamicity vs. Runtime type safetyDynamicity vs. Runtime type safety Time vs. spaceTime vs. space Flexibility vs. EfficiencyFlexibility vs. Efficiency

Ease of use vs. NormalizationEase of use vs. Normalization

Page 28: Oop concepts

Commonly Used Commonly Used FrameworksFrameworks

Struts/Tiles, JSF/MyFaces, Struts/Tiles, JSF/MyFaces, SpringSpring HibernateHibernate AJAX (GWT, DoJo)AJAX (GWT, DoJo) JSONJSON Webworks/Tapestry/Sitemesh/Turbine Webworks/Tapestry/Sitemesh/Turbine

(Velocity)(Velocity) Ruby on RailsRuby on Rails SOAP/Web servicesSOAP/Web services QuartzQuartz

Page 29: Oop concepts

AssertionsAssertions

Pre-conditionsPre-conditions Post-conditionsPost-conditions InvariantsInvariants