Thanks to visit codestin.com
Credit goes to www.slideshare.net

Eclipse as a framework of frameworks   (Please view in presentation mode for desired flow of information) Anshu Jain IBM Research - India [email_address] anshunjain {gmail, twitter, googlesites)
Introductions Cheating ‘Basic’ Exams => Programming is for Clerks => Java is so easy => Eclipse is easier => Programming is for lazy bums like me   First Job: Right here   IBM Research – The best research lab http://sites.google.com/site/anshunjain Your background
“ In  theory , there is no difference between  theory  and practice. But, in practice, there is” Jan La Van De Snepscheut
Motivation Move over hello world, shopping cart, ATM example From consumers to providers From provider to engine From servlets to servlets containers From eclipse plug-ins to eclipse platform From EJBs to EJB container From android apps to android platform Also driving  … back to OO..!!  … and a bit of agility..!! Nothing u don’t already know ..!!
What are we doing today Building a VERY simple calculator
V1 -  Monolithic Class
addFunctions private void addFunctions(Composite functionComposite) { Button addButton = new Button(functionComposite, SWT. NONE ); addButton.setText("+"); addButton.addSelectionListener(new ButtonSelectionListener("+")); addButton.setLayoutData(data); Button subtractButton = new Button(functionComposite, SWT. NONE ); subtractButton.addSelectionListener(new ButtonSelectionListener("-")); subtractButton.setLayoutData(data); subtractButton.setText("-"); Button multiplyButton = new Button(functionComposite, SWT. NONE ); multiplyButton.addSelectionListener(new ButtonSelectionListener("*")); multiplyButton.setLayoutData(data); multiplyButton.setText("*"); Button divideButton = new Button(functionComposite, SWT. NONE ); divideButton.addSelectionListener(new ButtonSelectionListener("/")); divideButton.setLayoutData(data); divideButton.setText("/"); } + - * /
executeOperation private   void  executeOperation() { // perform necessary operation and move on int  result = 0; inputNumberTwo  = Integer. parseInt ( text .getText()); if (currentOperation.equals("+")) { result = add(inputNumberOne, inputNumberTwo); } if (currentOperation.equals("-")) { result = subtract(inputNumberOne, inputNumberTwo); } if (currentOperation.equals("*")) { result = multiply(inputNumberOne, inputNumberTwo); } if (currentOperation.equals("/")) { result = divide(inputNumberOne, inputNumberTwo); } text .setText( ""  + result); }
The only constant - Change 1. Add new features – New functions 2. Fix existing features – Divide by Zero
The only constant – Change..!! private void addFunctions(Composite functionComposite) { … … Button xpoweryButton =  new  Button(functionComposite, SWT. NONE ); xpoweryButton.addSelectionListener( new  ButtonSelectionListener( "+" )); xpoweryButton.setLayoutData(data); xpoweryButton.setText( "x^y" ); Button modButton =  new  Button(functionComposite, SWT. NONE ); addButton.addSelectionListener( new  ButtonSelectionListener( "Mod" )); modButton.setLayoutData(data); modButton.setText( "Mod" ); private   int  divide( int  a,  int  b) { if  (b == 0) { text .setText( "DivideBy0 Error!" ); return  -1; }  else  { if  (a % b == 0) { text .setText( "Not absolute" ); return  a % b; } return  a / b; } }
The only constant – Change..!! New feature needs change in existing code New features can break existing code Fixes can break existing code
Changes cannot be avoided But they can be isolated Breakdown code into logical components Separation of concern
V2 Refactoring – Separation of concern
V2 Refactoring – Separation of Concern Encapsulation
Indirection vs. Separation Life is tougher: Now new features needs changes in multple classes Indirection is not separation Still writing a lot of redundant code Separation has to be logical Based on components (think objects..) Based on complete functionality or features
V3 – Thought ful Refactoring We still need to reference each function in calculator Code of createButton is common
V4 - Thoughtful Inheritance
The only constant  - Change New requirement Dynamic location of new functions Ask questions: Where should I look for it How do I know which new function has come How do I tell what is the name of that function How would I execute the function without knowing what it does
How to enable dynamic functions Where should I look for it In some predefined scope – folder, directory etc. How do I know which new function has come They should announce themselves to us How do I tell what is the name of that function They should announce the name How would I execute the function without knowing what it does There has to be a common language
Where to look for Any folder in my working directory becomes a function
Where to look for Nah..!! Not any folder..!!
V5 - Identification
V5 -  Invocation and Interaction The common language Interface
V5 – Dynamic Runtime - Dynamic loading of this jar (Classloading) - Dynamic instantiation of this class(Reflection)
V6 - Dynamic Discovery and Loading public void load(Calculator_Original calculator, String installDirectory) throws InstantiationException, IllegalAccessException { try { String[] nameOfFunctions =  loadFunctionsFromDirectory(installDirectory); IFunction[] functions =  new   IFunction[nameOfFunctions. length ]; MyCustomClassLoader loader =  new  MyCustomClassLoader( installDirectory); for  (IFunction function : functions) { Class functionClass = loader.loadClass( "" ); function = (IFunction)  functionClass.newInstance(); function.setCalculator(calculator); } } catch (ClassNotFoundException e) { // Handle this } }
V7 – providing a service Avoid scratch implementations Provide common functionalities in Base classes Provide any other housekeeping functions useful for all BaseFunction Math Library.!!
As if life wasn’t tough Discover folders and file Parse files for info Write your own Classloader   Learn reflection For what??? Building a VERY simple calculator But we already had one…!! Long ago..!   Building a calculator framework So we can make as complex calculators as we want, very simply... without worrying about all housekeeping
Revisiting our framework Separation of Concern Componentization Abstraction/Interface Registration and Discovery Dynamic Loading
What is a framework Framework– a basic reusable infrastructure or skeleton, on which various components integrate to provide a solution
What does a framework do Provide a component model Registration components tell they want to plug in Discovery framework finds out who wants to plug in Abstraction/Interface common protocol for interaction you don’t call me, I will call you Services required by most of the components, exposed by framework
Building another pluggable framework A dynamic signal processing tool – Matlab A dynamic java development tool – jBuilder A dynamic paint application – Gimp Your own custom framework – ?? The wheel re-invented
What does a framework do Provide a component model jars?, plugins?, bundles, activex components etc..  Registration Discovery File management, parsing, registry management Abstraction/Interface most modern programming languages Services file access services, jobs, scheduling, threading, user interfaces, etc etc..
Eclipse does all the above for u Eclipse is a  “framework of frameworks” Allows building a calculator framework Without you having to parse inputs Without you managing registries Without you worrying about dynamic classloading Without you working about housekeeping Eclipse allows you to create sockets, not just plug – in to sockets..!! Must Read: Notes to Eclipse Plugin Architecture: http://www.eclipse.org/articles/Article-Plug-in-architecture/plugin_architecture.html
Eclipse – framework for component model Component based OSGI Model Dependencies Lifecycle management Loading Your framework need not worry about Identification Scoping Loading jars Checking class paths
Component Model - Identification - add.cff - add.jar - Component Identifier - Component runtime info
Component Model - Identification BUNDLES - Manifest.MF - <bundlename>.jar - Bundle ID - Runtime Info: Classpath - blah..blah..
Component Model – OSGI Bundles  The API’s become almost intuitive
Component Model – Other APIs Framework for observing other components and services Resource and class loading Dynamic management of dependencies Hooks to component lifecycle  Service oriented component management
Framework for discovery Eclipse ‘plugins’ folder Eclipse plug-in registry infrastructure Allows you to create ‘sockets’ declaratively Matches ‘plugs’ that can fit in your ‘socket’ automatically Stores all extension information Your framework need not worry about File/Folder parsing XML Schema creation Managing data structures to store the extensions
Framework for discovery Who wants to let others extend them?  Who wants to extend? Who is extending me? Configuration provided by the extenders Properties of extenders I am lazy to even load the runtime Dynamic management of extenders
Eclipse – framework for abstraction/interface Naturally based on java Declaration of desired interfaces in plugin.xml Your framework need not worry about Verifying interface implementations
Eclipse – services for frameworks UI Toolkit MVC Architecture Component Management API’s XML/Help.. … on and on.. Your framework need not worry about Just about any service.. Some plug-in would provide that service
Eclipse – framework of frameworks Your application need not worry about Anything   Except for the core functionality your framework provides…like calculation
Closing thoughts Code, Code, Code Design patterns Understand reflection Understand how your containers, servers, providers work Think objects, eat objects, sleep objects…. https://sites.google.com/site/anshunjain/eclipse-presentations
Thank you

Understanding Framework Architecture using Eclipse

  • 1.
    Eclipse as aframework of frameworks (Please view in presentation mode for desired flow of information) Anshu Jain IBM Research - India [email_address] anshunjain {gmail, twitter, googlesites)
  • 2.
    Introductions Cheating ‘Basic’Exams => Programming is for Clerks => Java is so easy => Eclipse is easier => Programming is for lazy bums like me  First Job: Right here  IBM Research – The best research lab http://sites.google.com/site/anshunjain Your background
  • 3.
    “ In theory , there is no difference between theory and practice. But, in practice, there is” Jan La Van De Snepscheut
  • 4.
    Motivation Move overhello world, shopping cart, ATM example From consumers to providers From provider to engine From servlets to servlets containers From eclipse plug-ins to eclipse platform From EJBs to EJB container From android apps to android platform Also driving … back to OO..!! … and a bit of agility..!! Nothing u don’t already know ..!!
  • 5.
    What are wedoing today Building a VERY simple calculator
  • 6.
    V1 - Monolithic Class
  • 7.
    addFunctions private voidaddFunctions(Composite functionComposite) { Button addButton = new Button(functionComposite, SWT. NONE ); addButton.setText(&quot;+&quot;); addButton.addSelectionListener(new ButtonSelectionListener(&quot;+&quot;)); addButton.setLayoutData(data); Button subtractButton = new Button(functionComposite, SWT. NONE ); subtractButton.addSelectionListener(new ButtonSelectionListener(&quot;-&quot;)); subtractButton.setLayoutData(data); subtractButton.setText(&quot;-&quot;); Button multiplyButton = new Button(functionComposite, SWT. NONE ); multiplyButton.addSelectionListener(new ButtonSelectionListener(&quot;*&quot;)); multiplyButton.setLayoutData(data); multiplyButton.setText(&quot;*&quot;); Button divideButton = new Button(functionComposite, SWT. NONE ); divideButton.addSelectionListener(new ButtonSelectionListener(&quot;/&quot;)); divideButton.setLayoutData(data); divideButton.setText(&quot;/&quot;); } + - * /
  • 8.
    executeOperation private void executeOperation() { // perform necessary operation and move on int result = 0; inputNumberTwo = Integer. parseInt ( text .getText()); if (currentOperation.equals(&quot;+&quot;)) { result = add(inputNumberOne, inputNumberTwo); } if (currentOperation.equals(&quot;-&quot;)) { result = subtract(inputNumberOne, inputNumberTwo); } if (currentOperation.equals(&quot;*&quot;)) { result = multiply(inputNumberOne, inputNumberTwo); } if (currentOperation.equals(&quot;/&quot;)) { result = divide(inputNumberOne, inputNumberTwo); } text .setText( &quot;&quot; + result); }
  • 9.
    The only constant- Change 1. Add new features – New functions 2. Fix existing features – Divide by Zero
  • 10.
    The only constant– Change..!! private void addFunctions(Composite functionComposite) { … … Button xpoweryButton = new Button(functionComposite, SWT. NONE ); xpoweryButton.addSelectionListener( new ButtonSelectionListener( &quot;+&quot; )); xpoweryButton.setLayoutData(data); xpoweryButton.setText( &quot;x^y&quot; ); Button modButton = new Button(functionComposite, SWT. NONE ); addButton.addSelectionListener( new ButtonSelectionListener( &quot;Mod&quot; )); modButton.setLayoutData(data); modButton.setText( &quot;Mod&quot; ); private int divide( int a, int b) { if (b == 0) { text .setText( &quot;DivideBy0 Error!&quot; ); return -1; } else { if (a % b == 0) { text .setText( &quot;Not absolute&quot; ); return a % b; } return a / b; } }
  • 11.
    The only constant– Change..!! New feature needs change in existing code New features can break existing code Fixes can break existing code
  • 12.
    Changes cannot beavoided But they can be isolated Breakdown code into logical components Separation of concern
  • 13.
    V2 Refactoring –Separation of concern
  • 14.
    V2 Refactoring –Separation of Concern Encapsulation
  • 15.
    Indirection vs. SeparationLife is tougher: Now new features needs changes in multple classes Indirection is not separation Still writing a lot of redundant code Separation has to be logical Based on components (think objects..) Based on complete functionality or features
  • 16.
    V3 – Thoughtful Refactoring We still need to reference each function in calculator Code of createButton is common
  • 17.
    V4 - ThoughtfulInheritance
  • 18.
    The only constant - Change New requirement Dynamic location of new functions Ask questions: Where should I look for it How do I know which new function has come How do I tell what is the name of that function How would I execute the function without knowing what it does
  • 19.
    How to enabledynamic functions Where should I look for it In some predefined scope – folder, directory etc. How do I know which new function has come They should announce themselves to us How do I tell what is the name of that function They should announce the name How would I execute the function without knowing what it does There has to be a common language
  • 20.
    Where to lookfor Any folder in my working directory becomes a function
  • 21.
    Where to lookfor Nah..!! Not any folder..!!
  • 22.
  • 23.
    V5 - Invocation and Interaction The common language Interface
  • 24.
    V5 – DynamicRuntime - Dynamic loading of this jar (Classloading) - Dynamic instantiation of this class(Reflection)
  • 25.
    V6 - DynamicDiscovery and Loading public void load(Calculator_Original calculator, String installDirectory) throws InstantiationException, IllegalAccessException { try { String[] nameOfFunctions = loadFunctionsFromDirectory(installDirectory); IFunction[] functions = new IFunction[nameOfFunctions. length ]; MyCustomClassLoader loader = new MyCustomClassLoader( installDirectory); for (IFunction function : functions) { Class functionClass = loader.loadClass( &quot;&quot; ); function = (IFunction) functionClass.newInstance(); function.setCalculator(calculator); } } catch (ClassNotFoundException e) { // Handle this } }
  • 26.
    V7 – providinga service Avoid scratch implementations Provide common functionalities in Base classes Provide any other housekeeping functions useful for all BaseFunction Math Library.!!
  • 27.
    As if lifewasn’t tough Discover folders and file Parse files for info Write your own Classloader  Learn reflection For what??? Building a VERY simple calculator But we already had one…!! Long ago..!  Building a calculator framework So we can make as complex calculators as we want, very simply... without worrying about all housekeeping
  • 28.
    Revisiting our frameworkSeparation of Concern Componentization Abstraction/Interface Registration and Discovery Dynamic Loading
  • 29.
    What is aframework Framework– a basic reusable infrastructure or skeleton, on which various components integrate to provide a solution
  • 30.
    What does aframework do Provide a component model Registration components tell they want to plug in Discovery framework finds out who wants to plug in Abstraction/Interface common protocol for interaction you don’t call me, I will call you Services required by most of the components, exposed by framework
  • 31.
    Building another pluggableframework A dynamic signal processing tool – Matlab A dynamic java development tool – jBuilder A dynamic paint application – Gimp Your own custom framework – ?? The wheel re-invented
  • 32.
    What does aframework do Provide a component model jars?, plugins?, bundles, activex components etc.. Registration Discovery File management, parsing, registry management Abstraction/Interface most modern programming languages Services file access services, jobs, scheduling, threading, user interfaces, etc etc..
  • 33.
    Eclipse does allthe above for u Eclipse is a “framework of frameworks” Allows building a calculator framework Without you having to parse inputs Without you managing registries Without you worrying about dynamic classloading Without you working about housekeeping Eclipse allows you to create sockets, not just plug – in to sockets..!! Must Read: Notes to Eclipse Plugin Architecture: http://www.eclipse.org/articles/Article-Plug-in-architecture/plugin_architecture.html
  • 34.
    Eclipse – frameworkfor component model Component based OSGI Model Dependencies Lifecycle management Loading Your framework need not worry about Identification Scoping Loading jars Checking class paths
  • 35.
    Component Model -Identification - add.cff - add.jar - Component Identifier - Component runtime info
  • 36.
    Component Model -Identification BUNDLES - Manifest.MF - <bundlename>.jar - Bundle ID - Runtime Info: Classpath - blah..blah..
  • 37.
    Component Model –OSGI Bundles The API’s become almost intuitive
  • 38.
    Component Model –Other APIs Framework for observing other components and services Resource and class loading Dynamic management of dependencies Hooks to component lifecycle Service oriented component management
  • 39.
    Framework for discoveryEclipse ‘plugins’ folder Eclipse plug-in registry infrastructure Allows you to create ‘sockets’ declaratively Matches ‘plugs’ that can fit in your ‘socket’ automatically Stores all extension information Your framework need not worry about File/Folder parsing XML Schema creation Managing data structures to store the extensions
  • 40.
    Framework for discoveryWho wants to let others extend them? Who wants to extend? Who is extending me? Configuration provided by the extenders Properties of extenders I am lazy to even load the runtime Dynamic management of extenders
  • 41.
    Eclipse – frameworkfor abstraction/interface Naturally based on java Declaration of desired interfaces in plugin.xml Your framework need not worry about Verifying interface implementations
  • 42.
    Eclipse – servicesfor frameworks UI Toolkit MVC Architecture Component Management API’s XML/Help.. … on and on.. Your framework need not worry about Just about any service.. Some plug-in would provide that service
  • 43.
    Eclipse – frameworkof frameworks Your application need not worry about Anything  Except for the core functionality your framework provides…like calculation
  • 44.
    Closing thoughts Code,Code, Code Design patterns Understand reflection Understand how your containers, servers, providers work Think objects, eat objects, sleep objects…. https://sites.google.com/site/anshunjain/eclipse-presentations
  • 45.

Editor's Notes

  • #5 Board Exercise: What are the standard programs you have written so far ? Give examples…!!