1 When And How To Make Interfaces Work For You Advanced OO Techniques Alex Herbstritt Principal Software Engineer, Progress Software Session 102.

Презентация:



Advertisements
Похожие презентации
Structured Error Handling in the ABL Sarah Marshall QA Architect, OpenEdge Session 128.
Advertisements

2005 Pearson Education, Inc. All rights reserved. 1 Object-Oriented Programming: Interface.
© 2006 Cisco Systems, Inc. All rights reserved. HIPS v Administering Events and Generating Reports Managing Events.
© 2006 Cisco Systems, Inc. All rights reserved. MPLS v Complex MPLS VPNs Introducing Central Services VPNs.
© 2009 Avaya Inc. All rights reserved.1 Chapter Two, Voic Pro Components Module Two – Actions, Variables & Conditions.
Ребусы Свириденковой Лизы Ученицы 6 класса «А». 10.
PAT312, Section 16, December 2006 S16-1 Copyright 2007 MSC.Software Corporation SECTION 16 MATERIALS.
Workshop 11 Imprint - Assembly Meshing Wizard. WS11-2 Assembly Meshing Wizard Design goals One comprehensive user interface Intuitive approach for solid.
© 2005 Cisco Systems, Inc. All rights reserved. BGP v Customer-to-Provider Connectivity with BGP Connecting a Multihomed Customer to Multiple Service.
© 2006 Cisco Systems, Inc. All rights reserved. HIPS v Configuring Groups and Policies Configuring Policies.
Operator Overloading Customised behaviour of operators Chapter: 08 Lecture: 26 & 27 Date:
Yogesh Mehla Now concept of logic building is not so complex and not so simple. We will not work on how to make logic program in.
MOUSE MANIPULATION 23. The 3 button mouse is your tool for manipulation of the parts and assemblies that you have created. With it you can ZOOM, ROTATE.
Типовые расчёты Растворы
Урок повторения по теме: «Сила». Задание 1 Задание 2.
2005 Pearson Education, Inc. All rights reserved. 1 Object-Oriented Programming: Polymorphism.
1 Анна Юфкина Специалист по бизнес-решениям
Michael Jackson
Школьная форма Презентация для родительского собрания.
© 2006 Cisco Systems, Inc. All rights reserved. CVOICE v Configuring Voice Networks Configuring Dial Peers.
Транксрипт:

1 When And How To Make Interfaces Work For You Advanced OO Techniques Alex Herbstritt Principal Software Engineer, Progress Software Session 102

© 2009 Progress Software Corporation. All rights reserved. 2 A reference type (or specification) that specifies behavior an implementing class must provide A contract to which the implementing class must adhere Defines Methods Properties Grouped functionality Models multiple inheritance Interface – Standard Generic Definition BaseClass Implementer Interface

© 2009 Progress Software Corporation. All rights reserved. 3 A reference type (or specification) that specifies behavior an implementing class must provide A contract to which the implementing class must adhere Defines Methods Properties Grouped functionality Models multiple inheritance This doesnt tell one When or How to create them! Interface – Standard Generic Definition BaseClass Implementer Interface

© 2009 Progress Software Corporation. All rights reserved. 4 Why Use An Interface? Interfaces provide polymorphism across different types

© 2009 Progress Software Corporation. All rights reserved. 5 Why Use An Interface? || O>> Interfaces provide polymorphism across different types

© 2009 Progress Software Corporation. All rights reserved. 6 Why Use An Interface? Interfaces provide polymorphism across different types || O>> iPod VCR DVD 8-Track WMP

© 2009 Progress Software Corporation. All rights reserved. Use Cases For Interfaces Group common functionality across types Generic programming Class abstraction Client API 7

© 2009 Progress Software Corporation. All rights reserved. Distribute Common Functionality Interfaces define polymorphic behavior across disparate types Clients program to the contract of the interface The class fulfills the contract, decides the behavior 8

© 2009 Progress Software Corporation. All rights reserved. 9 Common Functionality INTERFACE IIterate: METHOD PUBLIC IIterate getNextEntry(). END INTERFACE.

© 2009 Progress Software Corporation. All rights reserved. 10 Common Functionality INTERFACE IIterate: METHOD PUBLIC IIterate getNextEntry(). END INTERFACE. BaseData Customer Form

© 2009 Progress Software Corporation. All rights reserved. 11 Common Functionality INTERFACE IIterate: METHOD PUBLIC IIterate getNextEntry(). END INTERFACE. IIterate BaseData Customer Form

© 2009 Progress Software Corporation. All rights reserved. 12 Common Functionality INTERFACE IIterate: METHOD PUBLIC IIterate getNextEntry(). END INTERFACE. getNextEntry() IIterate BaseData Customer Form

© 2009 Progress Software Corporation. All rights reserved. 13 Common Functionality DEFINE VARIABLE IIterRef AS IIterate. IIterRef = IIterRef:getNextEntry(). INTERFACE IIterate: METHOD PUBLIC IIterate getNextEntry(). END INTERFACE. IIterate BaseData Customer Form

© 2009 Progress Software Corporation. All rights reserved. Avoid Hierarchy Bloat Creating a base class with common functionality may introduce bloat. What happens when classes should not have a common base class but we want them to have common functionality? 14

© 2009 Progress Software Corporation. All rights reserved. 15 Polymorphism From Base Class METHOD Object getNextEntry() METHOD LOGICAL getDisplayValue() BaseData Customer Form XMLData

© 2009 Progress Software Corporation. All rights reserved. 16 Polymorphism From Base Class METHOD Object getNextEntry() METHOD LOGICAL getDisplayValue() BaseData Customer Form XMLData

© 2009 Progress Software Corporation. All rights reserved. 17 Polymorphism From Base Class METHOD Object getNextEntry() METHOD LOGICAL getDisplayValue() BaseData Customer Form XMLData

© 2009 Progress Software Corporation. All rights reserved. 18 Polymorphism From Base Class METHOD Object getNextEntry() METHOD LOGICAL getDisplayValue() BaseData Customer Form XMLData

© 2009 Progress Software Corporation. All rights reserved. 19 Polymorphism From Base Class CLASS Base: USING Progress.Lang.*. METHOD Object getNextEntry(): RETURN ?. END METHOD. METHOD LOGICAL getDisplayValue(): RETURN NO. END METHOD. /* and maybe others */ END CLASS.

© 2009 Progress Software Corporation. All rights reserved. 20 Polymorphism From Base Class CLASS Base: USING Progress.Lang.*. METHOD Object getNextEntry(): RETURN ?. END METHOD. METHOD LOGICAL getDisplayValue(): RETURN NO. END METHOD. /* and maybe others */ END CLASS. Base BaseData Customer Form XMLData

© 2009 Progress Software Corporation. All rights reserved. 21 Polymorphism From Base Class METHOD Object getNextEntry() METHOD LOGICAL getDisplayValue() BaseData Customer Form XMLData

© 2009 Progress Software Corporation. All rights reserved. 22 Polymorphism From Interfaces METHOD Object getNextEntry(). METHOD LOGICAL getDisplayValue(). IIterate IDisplay

© 2009 Progress Software Corporation. All rights reserved. 23 Polymorphism From Interfaces IIterate IDisplay BaseData Customer

© 2009 Progress Software Corporation. All rights reserved. 24 Polymorphism From Interfaces IIterate IDisplay BaseData Customer IIterate Form

© 2009 Progress Software Corporation. All rights reserved. 25 Polymorphism From Interfaces IIterate IDisplay BaseData Customer IIterate Form IDisplay XMLData

© 2009 Progress Software Corporation. All rights reserved. Clients Write Less/Easier Code Simplifies the client code Interfaces lower the dependency of the clients Clients need only know about the interface – Not the whole of all the types The value of abstraction –Implementations or hierarchies can change but will not impact clients 26

© 2009 Progress Software Corporation. All rights reserved. 27 Functionality Defined In A Class getDisplayValue() BaseData Customer XMLData

© 2009 Progress Software Corporation. All rights reserved. 28 METHOD PUBLIC LOGICAL displayInfo (INPUT objRef AS Progress.Lang.Object):

© 2009 Progress Software Corporation. All rights reserved. 29 METHOD PUBLIC LOGICAL displayInfo (INPUT objRef AS Progress.Lang.Object): DEFINE VARIABLE charVal AS CHARACTER INITIAL "". DEFINE VARIABLE plcRef AS CLASS Progress.Lang.Class. plcRef = objRef:getClass(). CASE plcRef:typeName: END CASE.... /* Do the work on charVal */...

© 2009 Progress Software Corporation. All rights reserved. 30 METHOD PUBLIC LOGICAL displayInfo (INPUT objRef AS Progress.Lang.Object): DEFINE VARIABLE charVal AS CHARACTER INITIAL "". DEFINE VARIABLE plcRef AS CLASS Progress.Lang.Class. plcRef = objRef:getClass(). CASE plcRef:typeName: WHEN "Customer" THEN charVal = CAST(objRef, "Customer"):getDisplayValue(). WHEN "XMLData" THEN charVal = CAST(objRef, "XMLData"):getDisplayValue(). END CASE.... /* Do the work on charVal */...

© 2009 Progress Software Corporation. All rights reserved. 31 Functionality Defined In Interface METHOD LOGICAL getDisplayValue(). BaseData Customer XMLData IDisplay

© 2009 Progress Software Corporation. All rights reserved. 32 METHOD PUBLIC LOGICAL displayInfo (INPUT objRef AS IDisplay):

© 2009 Progress Software Corporation. All rights reserved. 33 METHOD PUBLIC LOGICAL displayInfo (INPUT objRef AS IDisplay): DEFINE VARIABLE charVal AS CHARACTER. charVal = objRef:getDisplayValue().... /* Do the work on charVal */...

© 2009 Progress Software Corporation. All rights reserved. Service Defines Contract Designing interfaces from required functionality The service need not implement the interface Any class that wish to make use of the service is required to implement the interface 34

© 2009 Progress Software Corporation. All rights reserved. 35 METHOD PUBLIC CHARACTER getStringValue (INPUT InterRef AS ISerialize): DEFINE VARIABLE StringValue AS CHARACTER. StringValue = InterRef:getNameString() + "_" + STRING(InterRef:getUniqueID(), ">>9"). /* StringValue now looks like Name_001 */ RETURN StringValue.

© 2009 Progress Software Corporation. All rights reserved. 36 METHOD PUBLIC CHARACTER getStringValue (INPUT InterRef AS ISerialize): DEFINE VARIABLE StringValue AS CHARACTER. StringValue = InterRef:getNameString() + "_" + STRING(InterRef:getUniqueID(), ">>9"). /* StringValue now looks like Name_001 */ RETURN StringValue. INTERFACE ISerialize: METHOD PUBLIC CHARACTER getNameString(). METHOD PUBLIC INTEGER getUniqueID(). END INTERFACE.

© 2009 Progress Software Corporation. All rights reserved. Misconceptions Interfaces Do not limit additional behavior in the class Do not preclude programming to the class 37

© 2009 Progress Software Corporation. All rights reserved. 38 IIterate Definition INTERFACE IIterate: METHOD PUBLIC IIterate getNextEntry(). METHOD PUBLIC IIterate getPrevEntry(). DEFINE PROPERTY PUBLIC currentName AS CHARACTER GET. /* NO SET. */ END INTERFACE. IIterate

© 2009 Progress Software Corporation. All rights reserved. 39 Client Uses IIterate Reference /* CLIENT Snippet */ IIterRef = IIterRef:getPrevEntry(). CName = IIterRef:currentName. Form Customer IIterate

© 2009 Progress Software Corporation. All rights reserved. 40 Client Uses Customer Reference /* CLIENT Snippet */ IIterRef = CustRef:getPrevEntry(). CustRef:methodNotInInterface(). Form Customer IIterate

© 2009 Progress Software Corporation. All rights reserved. 41 Client Uses Form Reference /* CLIENT Snippet */ IIterRef = FormRef:getNextEntry(). FormRef:currentName = CName. Form Customer IIterate

© 2009 Progress Software Corporation. All rights reserved. 42 Client Uses Three Different References /* CLIENT Snippet */ IIterRef = IIterRef:getPrevEntry(). CName = IIterRef:currentName. IIterRef = CustRef:getPrevEntry(). CustRef:methodNotInInterface(). IIterRef = FormRef:getNextEntry(). FormRef:currentName = CName. Form Customer IIterate

© 2009 Progress Software Corporation. All rights reserved. Conclusion Define an interface to Group common functionality across types Allow classes to support multiple types Promote more generic programming Interfaces distribute polymorphic behavior across disparate types 43

44 When And How To Make Interfaces Work For You Advanced OO Techniques Alex Herbstritt Principal Software Engineer, Progress Software Session 102