SlideShare una empresa de Scribd logo
1 de 15
Paradigmas de Linguagens de Programação Paradigma Orientado a Aspectos Aula #9 (CopyLeft)2009 - Ismar Frango ismar@mackenzie.br
AOP A Programação Orientada por Aspectos (AOP), proposta por Gregor Kiczales em 1997 tem por objetivo modularizar decisões de projeto que não podem ser adequadamente definidas por meio da POO. Na AOP, requisitos de sistemas são modelados por meio de  classes , que implementam os objetos do mundo real,  e  aspectos , que implementam requisitos transversais do sistema
Benefícios da AOP ,[object Object],[object Object],[object Object],“ Programs that clearly express the design structure they implement are easier to maintain” Gregor Kiczales
Exemplo: Hello, world  (que novidade!)   class  Hello{ public static void  main(String args[ ]) {  System.out.println("Início da Monitoração");  System.out.println("Hello World!");  System.out.println("Final da monitoração"); } } Tangled code
Exemplo: Hello, world  (novidade!) aspect  Monitor{ pointcut  impressao(): execution  ( public static void  Hello.main(String [])); before (): impressao () { System.out.println("Inicio da impressao"); } after (): impressao () { System.out.println("Final da impressao"); }  } class  Hello{ public static void  main(String args[ ]){ System.out.println("Hello World!"); } } Hello.java Monitor.aj
Weaving Hello.java Monitor.aj ajc Hello.class Monitor.class
Exemplo: Logger OO Exemplo de Tirelo et al. – JAI2004
Exemplo: Logger AOP public aspect  LoggingAspect { pointcut  publicMethods():  execution  (public  * * (..)); pointcut  logObjectCalls() :  execution ( *  Logger. * (..)); pointcut  loggableCalls() : publicMethods()  && !  logObjectCalls(); before (): loggableCalls() { Logger.logEntry( thisJoinPoint.getSignature().toString()); } after () returning: loggableCalls() { Logger.logNormalExit( thisJoinPoint.getSignature().toString()); }
Exemplo: Disque-saúde com RMI Exemplo de Sérgio Soares e Paulo Borba - UFPE
Implementação com RMI public class Complaint  implements java.io.Serializable  { private String description; private Person complainer; ...  public Complaint(String description, Person complainer, ...) {  ... } public String getDescription() { return this.description; } public Person getComplainer() { return this.complainer; } public void setDescription(String desc) { this.description = desc; } public void setComplainer(Person complainer) { this.complainer = complainer; } ... } public class HealthWatcherFacade  implements IFacade  { public void update(Complaint complaint)  throws TransactionException, RepositoryException, ObjectNotFoundException, ObjectNotValidException { ... }  public static void main(String[] args) { try { HealthWatcherFacade facade = HealthWatcherFacade.getInstance(); System.out.println("Creating RMI server..."); UnicastRemoteObject.exportObject(facade);  java.rmi.Naming.rebind("/HealthWatcher"); System.out.println("Server created and ready."); } catch (RemoteException rmiEx) {... } catch (MalformedURLException rmiEx) { ...} catch(Exception ex) {... } } } public class ServletUpdateComplaintData extends HttpServlet { private  IFacade  facade; public void init(ServletConfig config) throws ServletException { try { facade = (IFacade) java.rmi.Naming.lookup("//HealthWatcher"); } catch (java.rmi.RemoteException rmiEx) {...} catch (java.rmi.NotBoundException rmiEx) {...} catch (java.net.MalformedURLException rmiEx) {...} } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ... facade.update(complaint); ... } ... } public class Person  implements java.io.Serializable  { private String nome; ... public Person(String nome, …) { this.nome   = nome; … } public String getNome() { return nome; } … } public interface IFacade extends java.rmi.Remote { public void updateComplaint complaint) throws TransactionException, RepositoryException, ObjectNotFoundException, ObjectNotValidException, RemoteException; . . .  }
Visão geral do código OO public class Complaint  implements java.io.Serializable  { private String description; private Person complainer; ...  public Complaint(String description, Person complainer, ...) {  ... } public String getDescription() { return this.description; } public Person getComplainer() { return this.complainer; } public void setDescription(String desc) { this.description = desc; } public void setComplainer(Person complainer) { this.complainer = complainer; } ... } public interface IFacade extends java.rmi.Remote { public void updateComplaint complaint) throws TransactionException, RepositoryException, ObjectNotFoundException, ObjectNotValidException, RemoteException; . . .  } public class HealthWatcherFacade  implements IFacade  { public void update(Complaint complaint)  throws TransactionException, RepositoryException, ObjectNotFoundException, ObjectNotValidException { ... }  public static void main(String[] args) { try { HealthWatcherFacade facade = HealthWatcherFacade.getInstance(); System.out.println("Creating RMI server..."); UnicastRemoteObject.exportObject(facade);  java.rmi.Naming.rebind("/HealthWatcher"); System.out.println("Server created and ready."); } catch (RemoteException rmiEx) {... } catch (MalformedURLException rmiEx) { ...} catch(Exception ex) {... } } } public class Person  implements java.io.Serializable  { private String nome; ... public Person(String nome, …) { this.nome   = nome; … } public String getNome() { return nome; } … } public class ServletUpdateComplaintData extends HttpServlet { private  IFacade  facade; public void init(ServletConfig config) throws ServletException { try { facade = (IFacade) java.rmi.Naming.lookup("//HealthWatcher"); } catch (java.rmi.RemoteException rmiEx) {...} catch (java.rmi.NotBoundException rmiEx) {...} catch (java.net.MalformedURLException rmiEx) {...} } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ... facade.update(complaint); ... } ... } Código RMI
Problemas na implementação OO ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Disque-saúde com AOP
Implementação em AspectJ public class Complaint { private String description; private Person complainer; ...  public Complaint(String description, Person complainer, ...) {  ... } public String getDescription() { return this.description; } public Person getComplainer() { return this.complainer; } public void setDescription(String desc) { this.description = desc; } public void setComplainer(Person complainer) { this.complainer = complainer; } } public class ServletUpdateComplaintData extends HttpServlet { private HealthWatcherFacade facade; public void init(ServletConfig config) throws ServletException { try { facade = HealthWatcherFacade.getInstance(); } catch (Exception ex) {...} } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ... } ... } public class Person { private String nome; ... public Person(String nome, ...) { this.matricula = matricula; ... } public String getNome() { return nome; } ... } public class HealthWatcherFacade { public void update(Complaint complaint)  throws TransactionException, RepositoryException, ObjectNotFoundException, ObjectNotValidException { ... } } public interface IFacade extends java.rmi.Remote { public void updateComplaint complaint) throws TransactionException, RepositoryException, ObjectNotFoundException, ObjectNotValidException, RemoteException; . . .  } aspect DistributionAspect { declare parents: HealthWatcherFacade implements IFacade; declare parents: Complaint || Person implements java.io.Serializable; public static void HealthWatcherFacade.main(String[] args) { try { HealthWatcherFacade facade = HealthWatcherFacade.getInstance(); System.out.println("Creating RMI server..."); UnicastRemoteObject.exportObject(facade);  java.rmi.Naming.rebind("/HealthWatcher"); System.out.println("Server created and ready."); } catch (RemoteException rmiEx) {...} catch (MalformedURLException rmiEx) {...} catch(Exception ex) {...} }  //segue... private IFacade remoteFacade; pointcut facadeMethodsExecution():  within(HttpServlet+) &&  execution(* HealthWatcherFacade.*(..)) && this(HealthWatcherFacade);  before(): facadeMethodsExecution()  { prepareFacade();} private synchronized void prepareFacade() { if (healthWatcher == null) { try {  remoteFacade = (IFacade) java.rmi.Naming.lookup("//HealthWatcher"); } catch (java.rmi.RemoteException rmiEx) {...} catch (java.rmi.NotBoundException rmiEx) {...} catch (java.net.MalformedURLException rmiEx) {...} } void around(Complaint complaint) throws TransactionException, RepositoryException ObjectNotFoundException,ObjectNotValidException: facadeRemoteExecutions()  && args(complaint)  && call(void update(Complaint)) { try {  remoteFacade.update(complaint); } catch (RemoteException rmiEx) {...} } }
Disque-Saúde em AOP : Visão geral public class Complaint { private String description; private Person complainer; ...  public Complaint(String description, Person complainer, ...) {  ... } public String getDescription() { return this.description; } public Person getComplainer() { return this.complainer; } public void setDescription(String desc) { this.description = desc; } public void setComplainer(Person complainer) { this.complainer = complainer; } } public interface IFacade extends java.rmi.Remote { public void updateComplaint complaint) throws TransactionException, RepositoryException, ObjectNotFoundException, ObjectNotValidException, RemoteException; . . .  } public class HealthWatcherFacade { public void update(Complaint complaint)  throws TransactionException, RepositoryException, ObjectNotFoundException, ObjectNotValidException { ... } } public class Person { private String nome; ... public Person(String nome, ...) { this.matricula = matricula; ... } public String getNome() { return nome; } ... } public class ServletUpdateComplaintData extends HttpServlet { private HealthWatcherFacade facade; public void init(ServletConfig config) throws ServletException { try { facade = HealthWatcherFacade.getInstance(); } catch (Exception ex) {...} } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ... } ... } aspect DistributionAspect { declare parents: HealthWatcherFacade implements IFacade; declare parents: Complaint || Person implements java.io.Serializable; public static void HealthWatcherFacade.main(String[] args) { try { HealthWatcherFacade facade = HealthWatcherFacade.getInstance(); System.out.println("Creating RMI server..."); UnicastRemoteObject.exportObject(facade);  java.rmi.Naming.rebind("/HealthWatcher"); System.out.println("Server created and ready."); } catch (RemoteException rmiEx) {...} catch (MalformedURLException rmiEx) {...} catch(Exception ex) {...} }  private IFacade remoteFacade; pointcut facadeMethodsExecution():  within(HttpServlet+) &&  execution(* HealthWatcherFacade.*(..)) && this(HealthWatcherFacade);  before(): facadeMethodsExecution()  {  prepareFacade();} private synchronized void prepareFacade() { if (healthWatcher == null) { try {  remoteFacade = (IFacade) java.rmi.Naming.lookup("//HealthWatcher"); } catch (java.rmi.RemoteException rmiEx) {...} catch (java.rmi.NotBoundException rmiEx) {...} catch (java.net.MalformedURLException rmiEx) {...} } void around(Complaint complaint) throws TransactionException, RepositoryExceptio n ObjectNotFoundException,ObjectNotValidException: facadeRemoteExecutions()  & &  args(complaint)  && call(void update(Complaint)) { try {  remoteFacade.update(complaint); } catch (RemoteException rmiEx) {...} } } Sistema local Aspectos de  Distribuição para RMI

Más contenido relacionado

La actualidad más candente

Pointcuts and Analysis
Pointcuts and AnalysisPointcuts and Analysis
Pointcuts and Analysis
Wiwat Ruengmee
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Mario Fusco
 

La actualidad más candente (20)

ITGM #9 - Коварный CodeType, или от segfault'а к работающему коду
ITGM #9 - Коварный CodeType, или от segfault'а к работающему кодуITGM #9 - Коварный CodeType, или от segfault'а к работающему коду
ITGM #9 - Коварный CodeType, или от segfault'а к работающему коду
 
Pro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScriptPro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScript
 
C++ aptitude
C++ aptitudeC++ aptitude
C++ aptitude
 
Exception handling
Exception handlingException handling
Exception handling
 
Algoritmos sujei
Algoritmos sujeiAlgoritmos sujei
Algoritmos sujei
 
Welcome to Modern C++
Welcome to Modern C++Welcome to Modern C++
Welcome to Modern C++
 
Ocl 09
Ocl 09Ocl 09
Ocl 09
 
JAVA OOP
JAVA OOPJAVA OOP
JAVA OOP
 
Java programs
Java programsJava programs
Java programs
 
Pointcuts and Analysis
Pointcuts and AnalysisPointcuts and Analysis
Pointcuts and Analysis
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
 
Core java
Core javaCore java
Core java
 
Oop objects_classes
Oop objects_classesOop objects_classes
Oop objects_classes
 
Java_practical_handbook
Java_practical_handbookJava_practical_handbook
Java_practical_handbook
 
C++aptitude questions and answers
C++aptitude questions and answersC++aptitude questions and answers
C++aptitude questions and answers
 
Java Programs
Java ProgramsJava Programs
Java Programs
 
report
reportreport
report
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumler
 
Modeling FSMs
Modeling FSMsModeling FSMs
Modeling FSMs
 
Presentacion clean code
Presentacion clean codePresentacion clean code
Presentacion clean code
 

Destacado

#latinproject @openeducationweek2014 - Methodologies
#latinproject @openeducationweek2014 - Methodologies#latinproject @openeducationweek2014 - Methodologies
#latinproject @openeducationweek2014 - Methodologies
Ismar Silveira
 

Destacado (20)

Paradigmas de Linguagens de Programacao- Aula #8
Paradigmas de Linguagens de Programacao- Aula #8Paradigmas de Linguagens de Programacao- Aula #8
Paradigmas de Linguagens de Programacao- Aula #8
 
Paradigmas de linguagens de programacao - aula#10
Paradigmas de linguagens de programacao - aula#10Paradigmas de linguagens de programacao - aula#10
Paradigmas de linguagens de programacao - aula#10
 
Engenharia de Software - Aula1
Engenharia de Software - Aula1Engenharia de Software - Aula1
Engenharia de Software - Aula1
 
Paradigmas De Linguagem De Programação.
Paradigmas De Linguagem De Programação.Paradigmas De Linguagem De Programação.
Paradigmas De Linguagem De Programação.
 
MOOC e Educação Aberta - Painel @ #cbie2013
MOOC e Educação Aberta - Painel @ #cbie2013MOOC e Educação Aberta - Painel @ #cbie2013
MOOC e Educação Aberta - Painel @ #cbie2013
 
Ismar webinar-udelar
Ismar webinar-udelarIsmar webinar-udelar
Ismar webinar-udelar
 
Um Sistema De Recomendacao para Web 2
Um Sistema De Recomendacao para Web 2Um Sistema De Recomendacao para Web 2
Um Sistema De Recomendacao para Web 2
 
#latinproject @openeducationweek2014 - Methodologies
#latinproject @openeducationweek2014 - Methodologies#latinproject @openeducationweek2014 - Methodologies
#latinproject @openeducationweek2014 - Methodologies
 
Apresentação WAvalia - SBIE 2009
Apresentação WAvalia - SBIE 2009Apresentação WAvalia - SBIE 2009
Apresentação WAvalia - SBIE 2009
 
wei2010
wei2010wei2010
wei2010
 
Interaccion2014 - Presentation about Open Books, MOOCs and Instructional Design
Interaccion2014 - Presentation about Open Books, MOOCs and Instructional DesignInteraccion2014 - Presentation about Open Books, MOOCs and Instructional Design
Interaccion2014 - Presentation about Open Books, MOOCs and Instructional Design
 
Mini-curso RubyOnRails CESOL
Mini-curso RubyOnRails CESOLMini-curso RubyOnRails CESOL
Mini-curso RubyOnRails CESOL
 
Sinatra - Primeiros Passos
Sinatra - Primeiros PassosSinatra - Primeiros Passos
Sinatra - Primeiros Passos
 
Fundcompsis 1.1
Fundcompsis 1.1Fundcompsis 1.1
Fundcompsis 1.1
 
E:\Plp 2009 2\Plp Aula11
E:\Plp 2009 2\Plp Aula11E:\Plp 2009 2\Plp Aula11
E:\Plp 2009 2\Plp Aula11
 
Paradigmas do Ruby
Paradigmas do RubyParadigmas do Ruby
Paradigmas do Ruby
 
Charla juegos udelar2015_vfinal
Charla juegos udelar2015_vfinalCharla juegos udelar2015_vfinal
Charla juegos udelar2015_vfinal
 
Paradigmas de Linguagens de Programacao - Aula #7
Paradigmas de Linguagens de Programacao - Aula #7Paradigmas de Linguagens de Programacao - Aula #7
Paradigmas de Linguagens de Programacao - Aula #7
 
Paradigmas de Linguagens de Programacao - Aula #5
Paradigmas de Linguagens de Programacao - Aula #5Paradigmas de Linguagens de Programacao - Aula #5
Paradigmas de Linguagens de Programacao - Aula #5
 
Lua para Jogos
Lua para JogosLua para Jogos
Lua para Jogos
 

Similar a Paradigmas de linguagens de programacao - aula#9

Better Software: introduction to good code
Better Software: introduction to good codeBetter Software: introduction to good code
Better Software: introduction to good code
Giordano Scalzo
 
Evolution and Examples of Java Features, from Java 1.7 to Java 22
Evolution and Examples of Java Features, from Java 1.7 to Java 22Evolution and Examples of Java Features, from Java 1.7 to Java 22
Evolution and Examples of Java Features, from Java 1.7 to Java 22
Yann-Gaël Guéhéneuc
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
Alexey Buzdin
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
C.T.Co
 

Similar a Paradigmas de linguagens de programacao - aula#9 (20)

比XML更好用的Java Annotation
比XML更好用的Java Annotation比XML更好用的Java Annotation
比XML更好用的Java Annotation
 
Using the Windows 8 Runtime from C++
Using the Windows 8 Runtime from C++Using the Windows 8 Runtime from C++
Using the Windows 8 Runtime from C++
 
Jersey Guice AOP
Jersey Guice AOPJersey Guice AOP
Jersey Guice AOP
 
Android workshop
Android workshopAndroid workshop
Android workshop
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
Java rmi
Java rmiJava rmi
Java rmi
 
Introduction to-java
Introduction to-javaIntroduction to-java
Introduction to-java
 
JDK Power Tools
JDK Power ToolsJDK Power Tools
JDK Power Tools
 
JDD 2016 - Sebastian Malaca - You Dont Need Unit Tests
JDD 2016 - Sebastian Malaca - You Dont Need Unit TestsJDD 2016 - Sebastian Malaca - You Dont Need Unit Tests
JDD 2016 - Sebastian Malaca - You Dont Need Unit Tests
 
Alexey Buzdin "Maslow's Pyramid of Android Testing"
Alexey Buzdin "Maslow's Pyramid of Android Testing"Alexey Buzdin "Maslow's Pyramid of Android Testing"
Alexey Buzdin "Maslow's Pyramid of Android Testing"
 
The definitive guide to java agents
The definitive guide to java agentsThe definitive guide to java agents
The definitive guide to java agents
 
Androidaop 170105090257
Androidaop 170105090257Androidaop 170105090257
Androidaop 170105090257
 
IKH331-07-java-rmi
IKH331-07-java-rmiIKH331-07-java-rmi
IKH331-07-java-rmi
 
Better Software: introduction to good code
Better Software: introduction to good codeBetter Software: introduction to good code
Better Software: introduction to good code
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?JVM Mechanics: When Does the JVM JIT & Deoptimize?
JVM Mechanics: When Does the JVM JIT & Deoptimize?
 
Evolution and Examples of Java Features, from Java 1.7 to Java 22
Evolution and Examples of Java Features, from Java 1.7 to Java 22Evolution and Examples of Java Features, from Java 1.7 to Java 22
Evolution and Examples of Java Features, from Java 1.7 to Java 22
 
Android Architecture Components
Android Architecture ComponentsAndroid Architecture Components
Android Architecture Components
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 

Más de Ismar Silveira

Más de Ismar Silveira (15)

REA - Recursos Educacionais Abertos
REA - Recursos Educacionais AbertosREA - Recursos Educacionais Abertos
REA - Recursos Educacionais Abertos
 
Fundamentos de Sistemas de informacao - Aula #16
Fundamentos de Sistemas de informacao - Aula #16Fundamentos de Sistemas de informacao - Aula #16
Fundamentos de Sistemas de informacao - Aula #16
 
Fundamentos de Sistemas de Informacao - Aula #14 2009_2
Fundamentos de Sistemas de Informacao - Aula #14 2009_2Fundamentos de Sistemas de Informacao - Aula #14 2009_2
Fundamentos de Sistemas de Informacao - Aula #14 2009_2
 
Fundamentos de Sistemas de Informacao - Aula 13
Fundamentos de Sistemas de Informacao - Aula 13Fundamentos de Sistemas de Informacao - Aula 13
Fundamentos de Sistemas de Informacao - Aula 13
 
Fundamentos de Sistemas de Informacao - Aula 11 2009_2
Fundamentos de Sistemas de Informacao - Aula 11 2009_2Fundamentos de Sistemas de Informacao - Aula 11 2009_2
Fundamentos de Sistemas de Informacao - Aula 11 2009_2
 
Fundamentos de Sistemas de Informacao - Aula 12 2009_2
Fundamentos de Sistemas de Informacao - Aula 12 2009_2Fundamentos de Sistemas de Informacao - Aula 12 2009_2
Fundamentos de Sistemas de Informacao - Aula 12 2009_2
 
Fundamentos de Sistemas de Informacao - Aula #10_2009_2
Fundamentos de Sistemas de Informacao - Aula #10_2009_2Fundamentos de Sistemas de Informacao - Aula #10_2009_2
Fundamentos de Sistemas de Informacao - Aula #10_2009_2
 
Fundamentos de Sistemas de Informacao - Aula #8_2009_2
Fundamentos de Sistemas de Informacao - Aula #8_2009_2Fundamentos de Sistemas de Informacao - Aula #8_2009_2
Fundamentos de Sistemas de Informacao - Aula #8_2009_2
 
Fundamentos de Sistemas de Informacao - Aula #8_2009_2
Fundamentos de Sistemas de Informacao - Aula #8_2009_2Fundamentos de Sistemas de Informacao - Aula #8_2009_2
Fundamentos de Sistemas de Informacao - Aula #8_2009_2
 
Fundamentos de Sistemas de Informacao - Aula #9_2009_2
Fundamentos de Sistemas de Informacao - Aula #9_2009_2Fundamentos de Sistemas de Informacao - Aula #9_2009_2
Fundamentos de Sistemas de Informacao - Aula #9_2009_2
 
Fundamentos de Sistemas de Informação - Aula #7
Fundamentos de Sistemas de Informação - Aula #7Fundamentos de Sistemas de Informação - Aula #7
Fundamentos de Sistemas de Informação - Aula #7
 
Paradigmas de Linguagens de Programacao - Aula #6
Paradigmas de Linguagens de Programacao - Aula #6Paradigmas de Linguagens de Programacao - Aula #6
Paradigmas de Linguagens de Programacao - Aula #6
 
Fundamentos de Sistemas de Informacao - Aula #7 - 2sem2009
Fundamentos de Sistemas de Informacao - Aula #7 - 2sem2009Fundamentos de Sistemas de Informacao - Aula #7 - 2sem2009
Fundamentos de Sistemas de Informacao - Aula #7 - 2sem2009
 
Fundamentos de Sistemas de Informacao - Aula 6
Fundamentos de Sistemas de Informacao - Aula 6Fundamentos de Sistemas de Informacao - Aula 6
Fundamentos de Sistemas de Informacao - Aula 6
 
Fundamentos de Sistemas de Informacao - Aula #5 (2009_2)
Fundamentos de Sistemas de Informacao - Aula #5 (2009_2)Fundamentos de Sistemas de Informacao - Aula #5 (2009_2)
Fundamentos de Sistemas de Informacao - Aula #5 (2009_2)
 

Último

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Último (20)

Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 

Paradigmas de linguagens de programacao - aula#9

  • 1. Paradigmas de Linguagens de Programação Paradigma Orientado a Aspectos Aula #9 (CopyLeft)2009 - Ismar Frango ismar@mackenzie.br
  • 2. AOP A Programação Orientada por Aspectos (AOP), proposta por Gregor Kiczales em 1997 tem por objetivo modularizar decisões de projeto que não podem ser adequadamente definidas por meio da POO. Na AOP, requisitos de sistemas são modelados por meio de classes , que implementam os objetos do mundo real, e aspectos , que implementam requisitos transversais do sistema
  • 3.
  • 4. Exemplo: Hello, world (que novidade!) class Hello{ public static void main(String args[ ]) { System.out.println("Início da Monitoração"); System.out.println("Hello World!"); System.out.println("Final da monitoração"); } } Tangled code
  • 5. Exemplo: Hello, world (novidade!) aspect Monitor{ pointcut impressao(): execution ( public static void Hello.main(String [])); before (): impressao () { System.out.println("Inicio da impressao"); } after (): impressao () { System.out.println("Final da impressao"); } } class Hello{ public static void main(String args[ ]){ System.out.println("Hello World!"); } } Hello.java Monitor.aj
  • 6. Weaving Hello.java Monitor.aj ajc Hello.class Monitor.class
  • 7. Exemplo: Logger OO Exemplo de Tirelo et al. – JAI2004
  • 8. Exemplo: Logger AOP public aspect LoggingAspect { pointcut publicMethods(): execution (public * * (..)); pointcut logObjectCalls() : execution ( * Logger. * (..)); pointcut loggableCalls() : publicMethods() && ! logObjectCalls(); before (): loggableCalls() { Logger.logEntry( thisJoinPoint.getSignature().toString()); } after () returning: loggableCalls() { Logger.logNormalExit( thisJoinPoint.getSignature().toString()); }
  • 9. Exemplo: Disque-saúde com RMI Exemplo de Sérgio Soares e Paulo Borba - UFPE
  • 10. Implementação com RMI public class Complaint implements java.io.Serializable { private String description; private Person complainer; ... public Complaint(String description, Person complainer, ...) { ... } public String getDescription() { return this.description; } public Person getComplainer() { return this.complainer; } public void setDescription(String desc) { this.description = desc; } public void setComplainer(Person complainer) { this.complainer = complainer; } ... } public class HealthWatcherFacade implements IFacade { public void update(Complaint complaint) throws TransactionException, RepositoryException, ObjectNotFoundException, ObjectNotValidException { ... } public static void main(String[] args) { try { HealthWatcherFacade facade = HealthWatcherFacade.getInstance(); System.out.println("Creating RMI server..."); UnicastRemoteObject.exportObject(facade); java.rmi.Naming.rebind("/HealthWatcher"); System.out.println("Server created and ready."); } catch (RemoteException rmiEx) {... } catch (MalformedURLException rmiEx) { ...} catch(Exception ex) {... } } } public class ServletUpdateComplaintData extends HttpServlet { private IFacade facade; public void init(ServletConfig config) throws ServletException { try { facade = (IFacade) java.rmi.Naming.lookup("//HealthWatcher"); } catch (java.rmi.RemoteException rmiEx) {...} catch (java.rmi.NotBoundException rmiEx) {...} catch (java.net.MalformedURLException rmiEx) {...} } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ... facade.update(complaint); ... } ... } public class Person implements java.io.Serializable { private String nome; ... public Person(String nome, …) { this.nome = nome; … } public String getNome() { return nome; } … } public interface IFacade extends java.rmi.Remote { public void updateComplaint complaint) throws TransactionException, RepositoryException, ObjectNotFoundException, ObjectNotValidException, RemoteException; . . . }
  • 11. Visão geral do código OO public class Complaint implements java.io.Serializable { private String description; private Person complainer; ... public Complaint(String description, Person complainer, ...) { ... } public String getDescription() { return this.description; } public Person getComplainer() { return this.complainer; } public void setDescription(String desc) { this.description = desc; } public void setComplainer(Person complainer) { this.complainer = complainer; } ... } public interface IFacade extends java.rmi.Remote { public void updateComplaint complaint) throws TransactionException, RepositoryException, ObjectNotFoundException, ObjectNotValidException, RemoteException; . . . } public class HealthWatcherFacade implements IFacade { public void update(Complaint complaint) throws TransactionException, RepositoryException, ObjectNotFoundException, ObjectNotValidException { ... } public static void main(String[] args) { try { HealthWatcherFacade facade = HealthWatcherFacade.getInstance(); System.out.println("Creating RMI server..."); UnicastRemoteObject.exportObject(facade); java.rmi.Naming.rebind("/HealthWatcher"); System.out.println("Server created and ready."); } catch (RemoteException rmiEx) {... } catch (MalformedURLException rmiEx) { ...} catch(Exception ex) {... } } } public class Person implements java.io.Serializable { private String nome; ... public Person(String nome, …) { this.nome = nome; … } public String getNome() { return nome; } … } public class ServletUpdateComplaintData extends HttpServlet { private IFacade facade; public void init(ServletConfig config) throws ServletException { try { facade = (IFacade) java.rmi.Naming.lookup("//HealthWatcher"); } catch (java.rmi.RemoteException rmiEx) {...} catch (java.rmi.NotBoundException rmiEx) {...} catch (java.net.MalformedURLException rmiEx) {...} } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ... facade.update(complaint); ... } ... } Código RMI
  • 12.
  • 14. Implementação em AspectJ public class Complaint { private String description; private Person complainer; ... public Complaint(String description, Person complainer, ...) { ... } public String getDescription() { return this.description; } public Person getComplainer() { return this.complainer; } public void setDescription(String desc) { this.description = desc; } public void setComplainer(Person complainer) { this.complainer = complainer; } } public class ServletUpdateComplaintData extends HttpServlet { private HealthWatcherFacade facade; public void init(ServletConfig config) throws ServletException { try { facade = HealthWatcherFacade.getInstance(); } catch (Exception ex) {...} } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ... } ... } public class Person { private String nome; ... public Person(String nome, ...) { this.matricula = matricula; ... } public String getNome() { return nome; } ... } public class HealthWatcherFacade { public void update(Complaint complaint) throws TransactionException, RepositoryException, ObjectNotFoundException, ObjectNotValidException { ... } } public interface IFacade extends java.rmi.Remote { public void updateComplaint complaint) throws TransactionException, RepositoryException, ObjectNotFoundException, ObjectNotValidException, RemoteException; . . . } aspect DistributionAspect { declare parents: HealthWatcherFacade implements IFacade; declare parents: Complaint || Person implements java.io.Serializable; public static void HealthWatcherFacade.main(String[] args) { try { HealthWatcherFacade facade = HealthWatcherFacade.getInstance(); System.out.println("Creating RMI server..."); UnicastRemoteObject.exportObject(facade); java.rmi.Naming.rebind("/HealthWatcher"); System.out.println("Server created and ready."); } catch (RemoteException rmiEx) {...} catch (MalformedURLException rmiEx) {...} catch(Exception ex) {...} } //segue... private IFacade remoteFacade; pointcut facadeMethodsExecution(): within(HttpServlet+) && execution(* HealthWatcherFacade.*(..)) && this(HealthWatcherFacade); before(): facadeMethodsExecution() { prepareFacade();} private synchronized void prepareFacade() { if (healthWatcher == null) { try { remoteFacade = (IFacade) java.rmi.Naming.lookup("//HealthWatcher"); } catch (java.rmi.RemoteException rmiEx) {...} catch (java.rmi.NotBoundException rmiEx) {...} catch (java.net.MalformedURLException rmiEx) {...} } void around(Complaint complaint) throws TransactionException, RepositoryException ObjectNotFoundException,ObjectNotValidException: facadeRemoteExecutions() && args(complaint) && call(void update(Complaint)) { try { remoteFacade.update(complaint); } catch (RemoteException rmiEx) {...} } }
  • 15. Disque-Saúde em AOP : Visão geral public class Complaint { private String description; private Person complainer; ... public Complaint(String description, Person complainer, ...) { ... } public String getDescription() { return this.description; } public Person getComplainer() { return this.complainer; } public void setDescription(String desc) { this.description = desc; } public void setComplainer(Person complainer) { this.complainer = complainer; } } public interface IFacade extends java.rmi.Remote { public void updateComplaint complaint) throws TransactionException, RepositoryException, ObjectNotFoundException, ObjectNotValidException, RemoteException; . . . } public class HealthWatcherFacade { public void update(Complaint complaint) throws TransactionException, RepositoryException, ObjectNotFoundException, ObjectNotValidException { ... } } public class Person { private String nome; ... public Person(String nome, ...) { this.matricula = matricula; ... } public String getNome() { return nome; } ... } public class ServletUpdateComplaintData extends HttpServlet { private HealthWatcherFacade facade; public void init(ServletConfig config) throws ServletException { try { facade = HealthWatcherFacade.getInstance(); } catch (Exception ex) {...} } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ... } ... } aspect DistributionAspect { declare parents: HealthWatcherFacade implements IFacade; declare parents: Complaint || Person implements java.io.Serializable; public static void HealthWatcherFacade.main(String[] args) { try { HealthWatcherFacade facade = HealthWatcherFacade.getInstance(); System.out.println("Creating RMI server..."); UnicastRemoteObject.exportObject(facade); java.rmi.Naming.rebind("/HealthWatcher"); System.out.println("Server created and ready."); } catch (RemoteException rmiEx) {...} catch (MalformedURLException rmiEx) {...} catch(Exception ex) {...} } private IFacade remoteFacade; pointcut facadeMethodsExecution(): within(HttpServlet+) && execution(* HealthWatcherFacade.*(..)) && this(HealthWatcherFacade); before(): facadeMethodsExecution() { prepareFacade();} private synchronized void prepareFacade() { if (healthWatcher == null) { try { remoteFacade = (IFacade) java.rmi.Naming.lookup("//HealthWatcher"); } catch (java.rmi.RemoteException rmiEx) {...} catch (java.rmi.NotBoundException rmiEx) {...} catch (java.net.MalformedURLException rmiEx) {...} } void around(Complaint complaint) throws TransactionException, RepositoryExceptio n ObjectNotFoundException,ObjectNotValidException: facadeRemoteExecutions() & & args(complaint) && call(void update(Complaint)) { try { remoteFacade.update(complaint); } catch (RemoteException rmiEx) {...} } } Sistema local Aspectos de Distribuição para RMI