Presentation is loading. Please wait.

Presentation is loading. Please wait.

Metodologías de Desarrollo de Software (Ciclo de Vida) Juan Carlos Olivares Rojas MSN:

Similar presentations

Presentation on theme: "Metodologías de Desarrollo de Software (Ciclo de Vida) Juan Carlos Olivares Rojas MSN:"— Presentation transcript:

1 Metodologías de Desarrollo de Software (Ciclo de Vida) Juan Carlos Olivares Rojas MSN: @jcolivares Social Network: Facebook, LinkedIn. Hi5

2 Agenda Introduction Aspect-Oriented Programming Fundamentals Examples

3 Software Development Today

4 Evolución del SW Software Evolution

5 Evolución del SW Software Evolution

6 Sw Development Problems A complex system can visualize like as combined implementation of multiple concerns

7 Sw Development Problems class Book { ….. … } class Partner { ….. } class Rent {….. }

8 class BookStore { private Book [] books ; private Partner [] partners; public BookStore() { … public void load( Partner p, Book b) { if validControlAccess() then{ // code of the method } else{ throwException(); } public void addPartner(Partner p){ if validContolAccess() then{ // code of the method } else{ throwException(); } // the rest of the class methods } Access Control Sw Development Problems

9 Tyranny of the Dominant Decomposition Descomposition by Form, Color or size We must choose only one principal model

10 Tyranny of the Dominant Decomposition Order by Form Order by Color

11 Color-Form Hierarchy We must elect one principal model. In this case: color and later, form

12 AOP Definition AOP was created by Gregor Kickzales and his Research Team at Palo Alto Research Center in 1996. “ An Aspect is a modular unit that is spreand in another functional units. The aspects exist in the design stage as in the implementación stage…” An Aspect is a concept that it’s difficult encapsulate clear and easily.

13 AOP An aspect is the unit which encapsulate a cross-cutting concern. AOP promoves the separation of concerns through mechanisms which abstract and compose this concepts troughout the system.

14 Traditional Structure of a Compiler

15 Compiling Process in POA

16 Program AOP Program Structure


18 AOP Advantages

19 POA Concepts JoinPointIt’s a well-defined position inside of object-oriented code, for instance, the declaración of a method. PointcutIt’s a set of conditions applied to a JoinPoint, when the conditions are true, it will active and execute an Execution Point asigned at this PointCut. AdviceIt’s a Fragment of Code tha it’s executed when is actived PointCut. AspectIt’s the combination of JoinPoint, Pointcuts and Advices.

20 Highlevel View of AspectJ Java Program AspectJ Advice pointcut advice body join point

21 An Aspect Definition Aspect Control { JoinPoint securityOperations = call s & calls BookStore.addPartner&... Before securityOperations: { if !=(validControlAcces()) then{ throwsExcepcion(); } }

22 AOP and OOP Relation Class A Class A1 Attb1 Attb2 Method 1 Clase A2 Attb 3 Method 1 Method 2 OOP: common concerns AOP: crosscuting concerns

23 OOP Evolution to AOP

24 AOP vs OOP

25 POA Advantages A code less complicated, more natural and more reduced. More facilities to think about the concerns, since they are separate and dependencies between them are minimal. An easier code to debug and to mantein.

26 AOP Tools Langauges for Programming Aspects: AspectJ: A Java Extension. The most popular. AspectC++, AspectS, CAESAR..NET Languages: Weave.NET, Source Weave.

27 Class Bank Problem public class Bank { // other declarations public double processDebit(long idAccount, double amount) { // openning a transaction try { // retrieve account // business validation // business logic associated with debit // persistencia del nuevo estado // traceo del movimiento para auditoria // cierre exitoso de la transacción (commit) return new amount account; } catch (Exception e) { // trace the audit exception // close abnormal transaction (rollback) // relauch the exception in superior layers } // other business process declarations } Transaction Persistence Traceability

28 Aspectual Descomposition Separation of concerns Aims to isolate cross cutting concerns Each one of these concerns will be implemented in a separate unit.

29 Aspectual Recomposition

30 AOP Bank Version public class Bank { // other declarations public double processDebit(long account, double amount) { // validaciones del negocio // debit business logic return new amount account; } // another business methods declarations } Transaccionalidad Persistencia Trazabilidad

31 Logging in org.apache.tomcat where is logging in –red shows lines of code that handle logging –not in just one place –not even in a small number of places logging is not modularized

32 Hello World with Aspects package; public class HW { private String message; public HW() { this.message = “Hello World"; } public void setMessge(String M){ this.menssage = M; } public String getMessage(){ return this.message; } public void showMessage(){ System.out.println(this.message); }

33 package; public class HelloWorld { public static void main(String[] args) { HW H; H= new HW(); H.showMenssage(); } Hello World with Aspects

34 package; public aspect Aspect { pointcut messagesToPrint() : call (void HW.showMessage()); before(): messagesToPrint(){ System.out.println(“Hi everybody!"); } after(): messagesToPrint(){ System.out.println(“Chao everybody!"); } Hello World with Aspects

35 Other Implementations import org.aspectj.lang.annotation.Aspect; @Aspect public class Aspecto {... } @ (" ( [ ]. ({ }) )")public void metodo() {... }

36 Other Implementations @Pointcut(" ( [ ]. ({ }) )")public void () {... } @ (" ()") public void metodo() {... }

37 Other Implementations @Before("execution(public void paquete.clase.metodo(String))") public void adviceEjemplo() { System.out.println("Antes del metodo"); }

38 Other Implementations @Pointcut("execution(public void paquete.clase.metodo(String))") public void pointcutEjemplo() {} @Before("pointcutEjemplo()") public void adviceEjemplo() { System.out.println("Antes del metodo"); }

39 Alternatives to Aspects Languages (OO, Componet-Based) Design Patterns Reflection

40 PointCut

41 When a particular method is executed: –execution(void Point.setX(int)) When a method is invocated: call(void Point.setX(int)) When a error handling is invocated: handler(ArrayOutOfBoundsException) When the object is actually executed: this(SomeType).

42 42 PointCut Examples When a method belongs to a class: –within(MyClass) When the JoinPoint is in the control flow of a call main method we need to use: cflow The target point refers to any possible JoinPoint

43 43 Pointcut Designator Wildcards It’s possible to use wildcards What do the next instructions do? –execution(* *(..)) –call(* set(..)) –execution(int *()) –call(* setY(long)) –call(* Point.setY(int)) –call(*.new(int, int))

44 PointCut JoinPoint Types –Methods –Constructors –Get/Set –Exception Handler a Line dispatch call join points execution join points

45 PointCut Examples We can applicate the next operations: or (“ || ”), and (“ && ”) and not (“ ! ”). Examples: – target(Point) && call(int *()) –call(* *(..)) && (within(Line) || within(Point)) –within(*) && execution(*.new(int)) –!this(Point) && call(int *(..))

46 46 Advice Type before advice after advice after returning after throwing around advice

47 47 Parameterized Advice We can acces to the context of a JoinPoint as follow: pointcut setXY(FigureElement fe, int x, int y): call(void FigureElement.setXY(int, int)) && target(fe) && args(x, y); after(FigureElement fe, int x, int y) returning: setXY(fe, x, y) { System.out.println(fe + " moved to (" + x + ", " + y + ")."); }

48 Another Example HistoryUpdating Display * 2 Point getX() getY() setX(int) setY(int) moveBy(int, int) Line getP1() getP2() setP1(Point) setP2(Point) moveBy(int, int) Figure makePoint(..) makeLine(..) FigureElement moveBy(int, int)

49 49 Another Example HTTPRequest HTTPResponse Servlet getCookies() getRequestURI()(doc) getSession() getRequestedSessionId()... getRequest() setContentType(contentType) getOutptutStream() setSessionId(id)... SessionInterceptor requestMap(request) beforeBody(req, resp)... Session getAttribute(name) setAttribute(name, val) invalidate()...

50 References Mejía, P. (2008), Programación Orientada a Aspectos, CINVESTAV, México. Quintero, A. (2000), Visión General de la Programación Orientada a Aspectos. Languages and Information System Department. Informatic and Estadistic Faculty, Sevilla University, Spain. Rodriguez M., POA, Gerente Relaciones Académicas, Microsoft Cono Sur

51 ¿Preguntas?

Download ppt "Metodologías de Desarrollo de Software (Ciclo de Vida) Juan Carlos Olivares Rojas MSN:"

Similar presentations

Ads by Google