صفحه 1:
| Aspect Oriented Patterns دانشگاه صنعتی امیر کبپر (یلی تکنیک تهران) پاییز ۸۹- چند ساعت قبل از شب یلدا

صفحه 2:
اتاریخچه برنامه نویسی جنبه گرا * _اولن بر توسطگریگو یزاس (پرفضوردنشگاه 196 در كثشور هلتد مطرح شد م وین اه رسمی از این موضوع ‎Mla lo‏ ای در یک کفراس اربایی در ره پا نامه نویسی شی ‎ad ple VA JLo Lb “Aspect-oriented programming‏ ®, eer, rata, Loo, LD, Lore O. oper, O. Deak, ‏اس وال90 اجه‎ ‏بوسر‎ 120. Oot od ©. Oxtrche, edie, Proveerkae oP ke Oxropes Ord wrewe a Ober ‎York, 107.‏ سل ‎rape OOD-OPO, Berbs, Leridbors, wad‏ 160 سا بو وق امین ‎0 ‏را تحت عنوان * ‏* . به تدریج با افزایش اقبال په سمت این تفکر [57۸()به وجود آمد . كه از برنامه نويسى جنبه كرا حمایت میکرد

صفحه 3:
[1] Kiczales, G. and Mezini, M. 2005. Aspect-oriented programming and modular reasoning. In Proceedings of ‘the 27th international Conference on Software Engineering (St. Louis, MO, USA, May 15-21, 2005), [2} Lippert, M. and Lopes, C. V. 2000. A study on exception detection and handling using aspect- oriented programming. In Proceedings of the 22nd international Conference on Software Engineering (Limerick, Ireland, June 04-11, 2000), [3] Noura El Maghawsy, Ahmed R.Dawood. Aspect Oriented GOF Design Patterns .In Proceedings of the The 7% International Conference on Informatics and Systems (INFOS), 2010, [4] Jan Hannemann and Gregor Kiczales. 2002. Design pattern implementation in Java and aspect]. In Proceedings of the 17th ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications (OOPSLA 02). [5] Eduardo Kessler Piveta and Lulz Carlos Zancanella. Observer Pattern using Aspect-Oriented Programming. In Proc. of the 3rd Latin American Conference on Pattern Languages of Programming, Porto de Galinhas, PE, Brazil, August 2003, [6] Radoslav Menkyna. Towards combining aspect-oriented design patterns.In Maria Bielikov’a, editor, Proc. Informatics and Information Technologies Student Research Conference, IIT:SRC 2007, pages 1- Bratislava, Slovakia, 2007. [7] Miles, Rs AspectJ Cookbook. O'Reilly, 2004. [8] Bruno Dufour, Christopher Goard, Laurie Hendren, Ooge de Moor, Ganesh Sittampalam, and Clark Verbrugge. 2004, Measuring the dynamic behaviour of Aspect programs. In Proceedings of the 19th annual ACM SIGPLAN ‘conference ‘on Object-oriented programming, systems, languages, and applications (OOPSLA ‘04).

صفحه 4:
Concern ® Tangling ° Cross-Cutting Concern °

صفحه 5:
Exception Handling 52 AOP 4538 ‏بررسى‎ مر سريرم افزارى ‎gad‏ از دب یافتن خ و بخورد با آن اختصاس ید پروسه به هم آميختن رفتار معمول و رفتار غير معمول در برنامهمیوندمنر به پدیده 60669 6۳۵55 8 شود تفكر 801 ميتوائد به تحو قابل توجهى حجم كد مربؤظ به برخورد با خظا را كاهش دهد بای نشان دادن این مطلب به ‎él»‏ ۴۲۵۲0۵۷۵۲ 1/۸۵۲[ رفته و أن را بازتويسى ميكنيم (1۳ * اللطالازيى/1/06 508:6 لسككه در دلنشكاء هابوركا لانت هيد شد و بعد ها حا لتقجرىيه خود كرفتو دارا يثراز ‎5٠٠‏ كاشرمبياشد: © براى نشان دادن قدرت ۰/۵08 کد 4/۵14[ با رويكرد جنبه كرا باز تويسى شد و مشاهده شد حجم کد مربوط به پرخورد خط به اندازه 3/4 كاهش بيدا كرده است.

صفحه 6:
ارائه یک مثال Class point 1 Static bool compare(point p1,pointp2){ if{p1 == null |] p2==null ) throw Exception("Arg Null Exception in Point.Compare”); } I end of compare(point p1,pointp2) }lend of Class point * _ فرض بگیرید 0000 کلاس دارید كه هر کدام 200 تابع با آرگومان از نوع 00[668 دارند : ( تعداذ مكازيسرخورد با خطا) 0 -12000 ( تسعداد خط كد براعيسرخورد با لينخطا) 0 * -24000

صفحه 7:
ارائه یک مثال Class point { Static boo! compare(point p1,pointp2){ } // end of compare(point. ۱ throw Exception(“Arg Null Exception in”+e.Name); }iend of aspect UpdateSignaling

صفحه 8:
Exception Introduction Pattern From the nature of aspects some design pattern can be added to another without the modification of the existing pattern. ( Exception Introduction , Policy ) Dublic abstract aspect ExceptoniniroductionAspet { abstract pointcut operations(); U pointcut operations defines where should exception occur. When this is defined as another design pattern exception introduction is used together with an existing patiern Mand any change of its code is required. Object around : operations) { try { return proceed); }eatch (CheckedException ex) { throw new RuntimeBixception(ex); 1 CheckedExceprion will be caught and nw runtime exception will be thrown, } * Adding pointcut design pattern to an advice design pattern requires usually a change in existing advice pattern.

صفحه 9:
بررسی برخی مدل های ارائه شده در کتاب 650۴ \ Cross Cutting Concern ‏گاهی مجرد سازی ب تنهابى قادر به كبسوله سازى‎ * * ادر بسيارى موارة 6806659 هابا كد اصلى جنان در هم مى أميزند كه عملا نمی تون ب نها به نان یک ماجول مستقل ناه كرد * اختلاط كد مربوط به ‎eek te pattern‏ رد تا اضاقه ويا حذف كردن أنها هزبته بر باشد. * در بياده سازى هاى صورت تكرفته از 8868677 های 660۴ در 1۷۵ مور افلیش ۳00/109۲310 و در 1۵۲ مور افزایش ‎reusability‏ را داشته ‎{rll‏ Jan Hannemann and Gregor Kiczales. 2002. Design pattern implementation in Java and aspeetJ. In Proceedings of the 17th ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications (OOPSLA *02).

صفحه 10:
پیاده سازی ۵0056۲۷6۲ با استفاده از 0۲16۳60 ]66 ک۸ Programming زمانى كه از 005611/©1 استفاده ميكنيم بايد تقيراتى را ذر كلاس هاى موجود يجاد كنيم : ConereteObserver piste) ‏سه‎ cbsoverStata زاو forall observers ‏رت‎ زد سم 0 ۳ Subject ‘AtachiQtservet) Deacty Observer) Natt!) ‏ده‎ ; ConcreteSubjact Gotta) O--+ SoiStaio) تست * Attach * Detach * Notify

صفحه 11:
interface Observer { void setSubject(Subject s); Subject getSubject(); void update(); interface Subject { void add(Observer obs); void remove(Observer obs); Vector getObservers(); Object getData();

صفحه 12:

صفحه 13:

صفحه 14:

صفحه 15:
پیاده سازی 0056۳۷6۲ با استفاده از 0۲16۳60 ]۸۵5۵66 ‎Programming‏ “<Aintorace>> Subject ‘<intrface>> Observer ‘Sacelods Onserven void ‘Sremove(ous : Observe) void Ssetsunjoctis: Subjecd “vole ‘Suetonserersd ObsenerT] ۱ | ‘SpetDatad ‏و مود‎ ee we <cAspacio> ObsenerPatern ‏تیه‎ ‘Observer {| server subject: Subject ay Class Any Coes Sexpoinicub> statechanges(s: Subjecd ‘S<<advice=> after(Subject 6); staleChanges(s)0 ‘Ssubjectada(ons | Observer) ۵ ‘Ssubjectrercve(ohs Obeere) Observer af ‏امه هو‎ ‏حابصم‎ 0 Concrete Subject 7 ۳ ع0 ] ‘Sceclare parents: ConersteSubject implements Subject ‘Sceclae parents: CancreteOhserve implements Observer ‘S<apointeut>» stateChanges(s: Subjec

صفحه 16:
پیاده سازی ۵0056۲۷6۲ با استفاده از 0۲16۳60 ]66 ک۸ ‎Programming‏ + Concrete Subject Store state information to be used by Concrete Observers. It does not, however, send notifications to its Observers. This responsibility is part of the Observer Pattern role. * Concrete Observers Servers as basis to field and method's introduction performed by the Observer Pattern. * Observer Pattern The Observer Pattern is an abstract aspect that encapsulate the behavior of the Observer pattern. The Observer Pattern contains the fields and methods to be included in the classes that are affected by the Concrete Observer Pattern. * Concrete Observer Pattern This participant specifies in what situations the Concrete Observers

صفحه 17:
پیاده سازی 0056۳۷6۲ با استفاده از 0۲16۳60 ]۸۵5۵66 ‎Programming‏ استفاده از تفكر جنبه كرا باعث ميشود كه بدون آنكه بدنه كلاس ها را تغبير دهيد ؛ يتونيد از مزاياى أن استفاده تماييد . © استفلده از تفكر جنبه كرا باعث ميشود تا كد مربوط به 010561۷/6۲ از كد اصلى برتامه جدا شود . * .با استفاده از اين روش /6 هاه 5لا»؟ را افزايش داده ايم زيرا ميتوان تنها با تفيير ‎gists concrete aspect‏ براى كلاس ‎la‏ ديكر نيز استفاده تمود. 0 15761 02 11

صفحه 18:
مزایای استفاده از رویکرد جنبه گرا در 6۳ 0056۳۷ Locality : All the code that implements the Observer pattern is in the abstract and concrete observer aspects none of it is in the participant classes. Reusability : The core pattern code is abstracted and reusable. The implementation of ObserverProtocol is generalizing the overall pattern behavior. Composition transparency : Because a pattern participant's implementation is not coupled to the pattern, if a Subject or Observer takes part in multiple observing relationships their code does not become more complicated and the pattern instances are not confused. Each instance of the pattern can be reasoned about independently. (Un)pluggability : Because Subjects and Observers need not be aware of their role in any pattern instance, it is possible to switch between using a pattern and not using it in the system.

صفحه 19:
بررسی برخی موارد خاص Multiple inheritance and Java : some of the patterns make use of multiple- ‘MediatorPattern (code) 2 ConcreteMediator (code) Colleague 1 wr ‏ی‎ Colleague 3 Colleague 3 Colleague 4 aspect) tt ‏ع3‎ Colleague 2 (code) Colleague 4 (code) inheritance in their implementation . The open class mechanism in Aspect] provides us with a more flexible way of implementing these patterns, as it allows to attach both interfaces and implementations (code) to existing ‘ConcreteMediator (code) Java classes. Colleague 1 (code) Colleague 3 (code)

صفحه 20:
Mediator The quick brown fox... Weight omodium @bold odemibold Slant Oroman italic oblique Cleon tensed

صفحه 21:
Aspect Oriented Patterns * Wormhole ٠» Exception Introduction © Participant * Cuckoo’s Egg ° Director ° Border Control * Policy ¢ Worker Object Creation

صفحه 22:
Cuckoo's Egg * Problem You want to override the type of object instantiated on a constructor call to. return an object of a different class transparently to the original business logic. اوه راومه وهای ‎ae‏ ‘Maintpplication 1 With the Choos Aspect the Sharedinetace reference (le poiming oan nance Replacersenass Sime det = new ign ۳5 ‏تا‎ ver |} “<interface>> = 7۳۳ ‏وه‎ Bet coratato a نا نمی رفس مرا ‎point atchConstucorall)‏ تست ۱ سس )

صفحه 23:
۳ و ‎Role!‏ tooth void Basinesstiassh 07 Deciare the inbertance relationship between BusinessCssA/Rolel and BusinessCass8/Role? ‘<<aspec>> DitectovAspect لحك ست > ‏دما‎ ‎Rolez 7 >64 SpecalizedAspect ‘eclare parents: BesinessClasc implements ‏عام‎ ‎declare parents BusinssClasB Implements Robe2 ۳ ae. bar) oid Provides any aditonal method Cs ‏کرد موز‎ required since the new interface & appied, that were nat ariginally part ofthe affected dass. Director public vid doSomthingole roles, Ls Toe? role} 1 | anything about the / inaplemestations of Role1 and Rae 2 :مهما امد

صفحه 24:
Border Control Design *Problem You want to formally define important regions within your application so your aspects can reuse those definitions to ensure they are only applied in the correct areas. <<aspect>> ‏سم‎ ‏ا‎ ‎+ paintcut withinApplicationPackagel) ! testing application prt tidied ‏ی سس‎ + ۵/0 ‏ع سح ز سس‎ + paintcut withinThirdPartyLibrary() ‘Maindpplication ۱ | ‏:وكا‎ [| ‘Any numberof regions canbe declared in| ‘the Border Controller in oder te spey regions of significance within your application

صفحه 25:
Border Control Design public aspect BorderControllerAspect { J+ * Specifies the testing region. */ public pointcut withinTestingRegion( ) : within(com.oreilly.aspectjcookbook.testing. [*** Specifies My Applications region. */ public pointcut withinMyApp( ) : within(com.ore! [*** Specifies a third party source code region. */ public pointcut withinThirdParty( ) : within(com.oreilly.aspectjcookbook.thirdpartylibrary.+); [+ * Specifies the applications main method. */ public pointcut withinMyAppMainMethod{ ) : withincode(public void oreilly.myapp.MyClass. main(..)); 1 aspectjcookbook. myapp.+); pointcut regionsOfinterest( ) : BorderControllerAspect.withinMyAppMainMethod ) || BorderControllerAspect.withinThirdParty( ) || BorderControllerAspect.withinTestingRegion( );

صفحه 26:
ation Of Aspect Patterns Aspects usually alter behavior of base concerns without requiring awareness on their side. This makes the combination of aspect-oriented design patterns easier than the combination of object oriented design patterns is ۳ ...- ‏متسر‎ ‎2 Policy Director Advice design ‏و0‎ ‏وت ی‎ Exception Introduction pointcut advice ee design pattern | design pattem ‘Creation pointeut ‘without change design pattern | change required advice ‘without without design pattem | change change

صفحه 27:
BenchMarks Quick Sort * Checking for return of null * Visitor * Strategy * Bean

صفحه 28:
Checking for return of null (First primitive pointeut matches all calls, second avoids those with void return type. pointcut methodsThatRetumObjects(): call(* *.*(.)) && leall(void *.*(.)); Object around(): methodsThatRetmmnObjects) { Object IRetVal = proceed(); if (IRetVal == null) { System.err-printin( “Detected null return value after calling * + thisJoinPoint.getSignature().toShortString) + * fn file ” + thisJoinPoint getSourceL ocation().getFileName() + ‏ات“‎ Line "+ thisJoinPoint.getSourcel ocation().getL.ine()); return IRetVal; 1

صفحه 29:
checking for return of null ‘Orig. | Checked | Orig Fixed Praned Jaa | Java Aspect Aspect} Aspect (oo nuit | (itt malt | (atl non-voie | (omy Objects | (ae within ciects) | checks) | metiods) | methods) _| aspect code) 7 Time (Seconds) TH] 150 WRT 11 17 4 inst, (million bytecodes) 856 | 6 4810 1869 1256 mem. alloc. (million bytes) 18 18 5612 1494 23 "APPLICATION ONLY lasses Toaded 2 2 WE, 1 [ instructions loaded 2207 | 21 13927 8183 7633 instructions dead gor | 105 6893 4959 4864 code coverage 60, 51 ost oe 0.36 ASPECT] TAG Mix (WHOLE PROGRAM) (2) DEFAULT () 5 BOT 7 ASPECT-CODE (28) 36 27 50. DVICEFRECUTE (I) 18 13 20 ADVICE_ARG-SETUP (2) 236 193 69 AROUND.CONVERSION (23) 67 07 10 AROUND_CATLBACK (24) 16.1 133 00 AROUND_PROCEED (25) 72 53 59 CLOSURE.INIT (26) 90 67 00 ‘Overhead foal) 517 65 11 pointcut methodsThatRewrObjects(): call(Object *.*(.)) && !within (ib.aspects..”):

صفحه 30:
‘Aspe 133 356 199 1 258 30 038 11 46.9 27 27 11 30 199 7 222 20 0.90 ‘WioLe PROGRAM ‘time (seconds) # insiructions (million bytecodes) ‘memory allocated (million bytes) Appricatton ONLY classes loaded instructions loaded instructions dead code coverage ASPECT) TAG MIx (WHOLE PROGRAM) ("0) DEFAULT (0) AspECT.cODE (28) TNTERMETHOD (14) ‘Overhead (total) Visitor

صفحه 31:
1 1837 1 7 (hash able) 177 2166 1 1 362 0 9 11 3 ‘Or o7 17 (OLE PROGRAM) YTECODES) 235 1913, 21 18 1 1932 23 5 aig 30 0.86 ‘AsrEcr] Tac wix (WHOLE PEOGEAN) Overhead (otal INSTRUCTION COUNT BREAKDOWN (WHL (tL. L10 Twa 1932 Aspect body Real” cade (oral) 17 Strategy Wiioir PRocRant Tie (scons) Insuetions(nllion byteeodes) allocated (milion bytes) ‘APPLICATION ONLY ‘lasses loaded instuctions loaded instructions dead code coverage 1۳۳۸۱0 ۳ 0 (TY ADVICE_ARG.SETUP (2) InreRFHELDGET (15) InreRFIEL set (16) Ovechead (ota)

صفحه 32:
AOSD-Europe age) Viije Universiteit ww ‘russel Katholieke Univer Leuven CeUVEN “SLOVAK UNIVERSITY OF TECHNOLOGY IN BRATISLAVA, GG TCHNGCHE Technische * UNIVERSITAT Universitaet S parwstact Darmstadt Siemens SIEMENS | ktiongesellschaft xcs. iy | MEN = _ ۱ = 3 Coordinator: ‘The University of Lancaster LANCASTER Trinity Cotege Dub a eM ۰ TEM, ‏ت۳۳‎ م د ب« / Institut National de Recherche en Informatique et en Automatique ۱۳۳ ‏مع‎ ‎Tl ad 2

صفحه 33:
[1] Kiczales, G. and Mezini, M. 2005. Aspect-oriented programming and modular reasoning. In Proceedings of ‘the 27th international Conference on Software Engineering (St. Louis, MO, USA, May 15-21, 2005), [2} Lippert, M. and Lopes, C. V. 2000. A study on exception detection and handling using aspect- oriented programming. In Proceedings of the 22nd international Conference on Software Engineering (Limerick, Ireland, June 04-11, 2000), [3] Noura El Maghawsy, Ahmed R.Dawood. Aspect Oriented GOF Design Patterns .In Proceedings of the The 7% International Conference on Informatics and Systems (INFOS), 2010, [4] Jan Hannemann and Gregor Kiczales. 2002. Design pattern implementation in Java and aspect]. In Proceedings of the 17th ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications (OOPSLA 02). [5] Eduardo Kessler Piveta and Lulz Carlos Zancanella. Observer Pattern using Aspect-Oriented Programming. In Proc. of the 3rd Latin American Conference on Pattern Languages of Programming, Porto de Galinhas, PE, Brazil, August 2003, [6] Radoslav Menkyna. Towards combining aspect-oriented design patterns.In Maria Bielikov’a, editor, Proc. Informatics and Information Technologies Student Research Conference, IIT:SRC 2007, pages 1- Bratislava, Slovakia, 2007. [7] Miles, Rs AspectJ Cookbook. O'Reilly, 2004. [8] Bruno Dufour, Christopher Goard, Laurie Hendren, Ooge de Moor, Ganesh Sittampalam, and Clark Verbrugge. 2004, Measuring the dynamic behaviour of Aspect programs. In Proceedings of the 19th annual ACM SIGPLAN ‘conference ‘on Object-oriented programming, systems, languages, and applications (OOPSLA ‘04).

صفحه 34:

صفحه 35:
Lene, O. ®., Parra .O., Daren, P. O., 20d Laren, 0.0. 0008. ‏امه رس‎ ‏مومس ۰ مومت فص موم‎ of hr Ocal Derober mt Penny ‏سوم‎ ‏سوه‎ (Porkanl, Octe, shiy CO - 20, ADDO). UPHOP WO. BOO, Deus Verk, OY, 99-99, 001 ‏سنا‎ AD ۱۱۵0۸۳۵۵۲۸۵۳۵۵۵۵

‏Aspect Oriented ‏Patterns محمد مهدی طالبی دانشگاه صنعتی امیرکبیر (پلی تکنیک تهران) پاییز -89چند ساعت قبل از شب یلدا اتاریخچه برنامه نویسی جنبه گرا . در کشور هلند مطرح شد،) UBC اولین بار توسط گريگور كيزالس (پروفسور دانشگاه  ” اولين ارائه رسمي از اين موضوع طی مقاله ای در یک کنفرانس اروپایی در رابطه با برنامه نویسی شئ گرا تحت عنوان . مطرح شد1997 “ طی سالAspect-oriented programming  G. Kiczales, J. Irwin, J. Lamping, J.-M. Loingtier,C. Lopes, C. Maeda, and A.Menhdhekar. Aspect-oriented programming. In M. Ak¸sit and S. Matsuoka, editors, Proceedings of the European Conference on ObjectOriented Programming, volume 1241, pages 220–242, Berlin, Heidelberg, and New York, 1997. Springer-Verlag. . که از برنامه نویسی جنبه گرا حمایت میکرد، به وجود آمدAspectJ به تدریج با افزایش اقبال به سمت این تفکر 2  منابع [1] Kiczales, G. and Mezini, M. 2005. Aspect-oriented programming and modular reasoning. In Proceedings of the 27th international Conference on Software Engineering (St. Louis, MO, USA, May 15 - 21, 2005). [2] Lippert, M. and Lopes, C. V. 2000. A study on exception detection and handling using aspect- oriented programming. In Proceedings of the 22nd international Conference on Software Engineering (Limerick, Ireland, June 04 - 11, 2000). [3] Noura El Maghawry, Ahmed R.Dawood. Aspect Oriented GOF Design Patterns .In Proceedings of the The 7th International Conference on Informatics and Systems (INFOS), 2010 . [4] Jan Hannemann and Gregor Kiczales. 2002. Design pattern implementation in Java and aspectJ. In Proceedings of the 17th ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications (OOPSLA `02). [5] Eduardo Kessler Piveta and Luiz Carlos Zancanella. Observer Pattern using Aspect-Oriented Programming. In Proc. of the 3rd Latin American Conference on Pattern Languages of Programming, Porto de Galinhas, PE, Brazil, August 2003. [6] Radoslav Menkyna. Towards combining aspect-oriented design patterns.In M´aria Bielikov´a, editor, Proc. Informatics and Information Technologies Student Research Conference, IIT.SRC 2007, pages 1–8, Bratislava,Slovakia, 2007. [7] Miles, R.: AspectJ Cookbook. O’Reilly, 2004. 3 [8] Bruno Dufour, Christopher Goard, Laurie Hendren, Oege de Moor, Ganesh Sittampalam, and Clark Verbrugge. 2004. Measuring the dynamic behaviour of AspectJ programs. In Proceedings of the 19th annual ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications (OOPSLA '04). تعاریف اولیه 4 Concern  Tangling  Cross-Cutting Concern  بررسی قدرت AOPدر Exception Handling ‏ در هر نرم افزاری قسمKتی از کد به یافتن خطا و برخورد با آن اختصاص میابد . ‏ پروسه به هم آمیختن رفتار معمول و رفتار غیر معمول در برنامه میتواند منجر به پدیده Cross Cutting Concernشود . ‏ تفکر AOPمیتواند به نحو قابل توجهی حجم کد مربوط به برخورد با خطا را کاهش دهد برای نشان دادن این مطلب به سراغ JWAM Frameworkرفته و آن را بازنویسی میکنیم [.]2 ‏ JWAMیک FrameworkاKسKتکه Kدر داKنKشگاه KهامKبورKگآKKلمانتKKهیه KشKKد و بKKعKد ها حKاKKلتتKKجارKیبKKه KخKود گKKرفKتو داراKیبKKیشاز 600کالسمKیباشد . ‏ برای نشان دادن قدرت ، AOPکد JWAMبا رویکرد جنبه گرا باز نویسی شد و مشاهده شد حجم کد مربوط به برخورد با خطا به اندازه ¼ کاهش پیدا کرده است. 5 ارائه یک مثال Class point { Static bool compare(point p1,pointp2){ if(p1 == null || p2==null ) throw Exception(“Arg Null Exception in Point.Compare”); …. } // end of compare(point p1,pointp2) . . . }//end of Class point : دارندObject تابع با آرگومان از نوع20 کالس دارید که هر کدام600 فرض بگیرید 12000= 20*600 24000= 2*12000 6 () ت\\\ع\داد مکانب\\\رخورد ب\\\ا خطا () ت\\\ع\داد خط ک\\\د ب\\\را\یب\\\رخورد ب\\\ا ا\ینخطا  ارائه یک مثال Class point { Static bool compare(point p1,pointp2){ …. } // end of compare(point. . Point.*() . . Aspect }//end of Class point  0 0 0 4 2 10 Point.Set*(int,int) PointCut /************************************<Aspect>******************************************/ aspect ExceptionHandler { pointcut HasObjArg(data e, Args *args): execution(void *.*(*)) ) && target(e) before(data e , Args *args) : HasObjArg () { if ( chkArgnull(Args) == true ) Advice throw Exception(“Arg Null Exception in”+e.Name); } 7 }//end of aspect UpdateSignaling Exception Introduction Pattern From the nature of aspects some design pattern can be added to another without the modification of the existing pattern. ( Exception Introduction , Policy )   8 Adding pointcut design pattern to an advice design pattern requires usually a change in existing advice pattern. بررسی برخی مدل های ارائه شده در کتاب GOF ‏ گاهی مجرد سازی به تنهایی قادر به کپسوله سازی Cross Cutting Concernها نیست. ‏ در بسیاری موارد patternها با کد اصلی چنان در هم می آمیزند که عمال نمی توان به آنها به عنوان یک ماجول مستقل نگاه کرد. ‏ اختالط کد مربوط به patternها باعث میگردد تا اضافه و یا حذف کردن آنها هزینه بر باشد. ‏ در پیاده سازی های صورت گرفته از patternهای GOFدر %75موارد افزایش modularityو در %52موارد افزایش reusabilityرا داشته ایم[. ]4 ‏Jan Hannemann and Gregor Kiczales. 2002. Design pattern implementation in ‏Java and aspectJ. In Proceedings of the 17th ACM SIGPLAN conference on ‏Object-oriented programming, systems, languages, and applications (OOPSLA `02). 9 پیاده سازی Observerبا استفاده از Aspect Oriented ‏Programming زمانی که از observerاستفاده میکنیم باید تغییراتی را در کالس های موجود ایجاد کنیم : ‏Attach ‏ ‏Detach ‏ ‏Notify ‏ 10 ارائه یک مثال interface Observer { void setSubject(Subject s); Subject getSubject(); void update(); } interface Subject { void add(Observer obs); void remove(Observer obs); Vector getObservers(); Object getData(); } 11 ارائه یک مثال public class Celsius{ private double degrees; public double getDegrees() { return degrees; } public void setDegrees(double aDegrees) { degrees = aDegrees; } Celsius(double aDegrees){ setDegrees(aDegrees); } } public class Thermometer{ private Celsius tempSource; public void setTempSource(Celsius atempSource){tempSource = atempSource;} public Celsius getTempSource(){ return tempSource; } public void drawTemperature(){} } public class CelsiusThermometer extends Thermometer{ public void drawTemperature(){ System.out.println("Temperature in Celsius"+ getTempSource().getDegrees()); } 12 } public class FahrenheitThermometer extends Thermometer{ public void drawTemperature(){ System.out.println("Temperature in Fahrenheit:"+ (1.8 * getTempSource().getDegrees())+32);} } ارائه یک مثال abstract aspect ObserverPattern { abstract pointcut stateChanges(Subject s); after(Subject s): stateChanges(s) { for (int i = 0; i < s.getObservers().size(); i++) ((Observer)s.getObservers().elementAt(i)).update(); } private Vector Subject.observers = new Vector(); public void Subject.add(Observer obs) { observers.addElement(obs); obs.setSubject(this); } public void Subject.remove(Observer obs) { observers.removeElement(obs); obs.setSubject(null); } public Vector Subject.getObservers() { return observers; } private Subject Observer.subject = null; public void Observer.setSubject(Subject s) { subject = s; } public Subject Observer.getSubject() { return subject; } } 13 ارائه یک مثال aspect ObserverPatternImpl extends ObserverPattern { declare parents: Celsius implements Subject; public Object Celsius.getData() { return this; } declare parents: Thermometer implements Observer; public void Thermometer.update() { drawTemperature(); } pointcut stateChanges(Subject s): target(s) && call(void Celsius.setDegrees(..)); } 14 Aspect Oriented با استفاده ازObserver پیاده سازی Programming 15 Aspect Oriented با استفاده ازObserver پیاده سازی Programming Concrete Subject Store state information to be used by Concrete Observers. It does not, however, send notifications to its Observers. This responsibility is part of the Observer Pattern role.  Concrete Observers Servers as basis to field and method’s introduction performed by the Observer Pattern.  Observer Pattern The Observer Pattern is an abstract aspect that encapsulate the behavior of the Observer pattern. The Observer Pattern contains the fields and methods to be included in the classes that are affected by the Concrete Observer Pattern.  16  Concrete Observer Pattern This participant specifies in what situations the Concrete Observers پیاده سازی Observerبا استفاده از Aspect Oriented ‏Programming ‏ استفاده از تفکر جنبه گرا باعث میشود که بدون آنکه بدنه کالس ها را تغییر دهید ،بتوانید از مزایای آن استفاده نمایید . ‏ استفاده از تفکر جنبه گرا باعث میشود تا کد مربوط به observerاز کد اصلی برنامه جدا شود . ‏ با استفاده از این روش reusabilityرا افزایش داده ایم زیرا میتوان تنها با تغییر concrete aspectها از آن برای کالس های دیگر نیز استفاده نمود. 17 Observer مزایای استفاده از رویکرد جنبه گرا در  Locality : All the code that implements the Observer pattern is in the abstract and concrete observer aspects,none of it is in the participant classes.  Reusability  Composition transparency : Because a pattern participant’s implementation The core pattern code is abstracted and reusable. The implementation of ObserverProtocol is generalizing the overall pattern behavior. : is not coupled to the pattern, if a Subject or Observer takes part in multiple observing relationships their code does not become more complicated and the pattern instances are not confused. Each instance of the pattern can be reasoned about independently.  (Un)pluggability : Because Subjects and Observers need not be aware of their role in any pattern instance, it is possible to switch between using a pattern and not using it in the system. 18 بررسی برخی موارد خاص   19 Multiple inheritance and Java : some of the patterns make use of multipleinheritance in their implementation . The open class mechanism in AspectJ provides us with a more flexible way of implementing these patterns, as it allows to attach both interfaces and implementations (code) to existing classes. Breaking cyclic dependencies : In the AspectJ implementation ,the indirection introduced by the ConcreteMediator aspect removes the cyclic dependencies. Java aspectJ Mediator 20 Aspect Oriented Patterns 21  Wormhole  Exception Introduction  Participant  Cuckoo’s Egg  Director  Border Control  Policy  Worker Object Creation Cuckoo's Egg  Problem You want to override the type of object instantiated on a constructor call to return an object of a different class transparently to the original business logic. 22 Director  Problem You want to define a set of roles to be implemented by unknown sets of application classes so they can be interacted with generically by an abstract aspect. 23 Border Control Design Problem You want to formally define important regions within your application so your aspects can reuse those definitions to ensure they are only applied in the correct areas. 24 Border Control Design public aspect BorderControllerAspect { /** * Specifies the testing region. */ public pointcut withinTestingRegion( ) : within(com.oreilly.aspectjcookbook.testing. +); /** * Specifies My Applications region. */ public pointcut withinMyApp( ) : within(com.oreilly.aspectjcookbook. myapp.+); /** * Specifies a third party source code region. */ public pointcut withinThirdParty( ) : within(com.oreilly.aspectjcookbook.thirdpartylibrary.+); /** * Specifies the applications main method. */ public pointcut withinMyAppMainMethod( ) : withincode(public void oreilly.myapp.MyClass. main(..)); } pointcut regionsOfInterest( ) : BorderControllerAspect.withinMyAppMainMethod( ) || BorderControllerAspect.withinThirdParty( ) || BorderControllerAspect.withinTestingRegion( );. 25 Combination Of Aspect Patterns  26 Aspects usually alter behavior of base concerns without requiring awareness on their side. This makes the combination of aspect-oriented design patterns easier than the combination of object oriented design patterns is. BenchMarks 27  Quick Sort  Checking for return of null  Visitor  Strategy  Bean Checking for return of null 28 checking for return of null 29 Visitor 30 Strategy 31 AOSD-Europe 32 منابع [1] Kiczales, G. and Mezini, M. 2005. Aspect-oriented programming and modular reasoning. In Proceedings of the 27th international Conference on Software Engineering (St. Louis, MO, USA, May 15 - 21, 2005). [2] Lippert, M. and Lopes, C. V. 2000. A study on exception detection and handling using aspect- oriented programming. In Proceedings of the 22nd international Conference on Software Engineering (Limerick, Ireland, June 04 - 11, 2000). [3] Noura El Maghawry, Ahmed R.Dawood. Aspect Oriented GOF Design Patterns .In Proceedings of the The 7th International Conference on Informatics and Systems (INFOS), 2010 . [4] Jan Hannemann and Gregor Kiczales. 2002. Design pattern implementation in Java and aspectJ. In Proceedings of the 17th ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications (OOPSLA `02). [5] Eduardo Kessler Piveta and Luiz Carlos Zancanella. Observer Pattern using Aspect-Oriented Programming. In Proc. of the 3rd Latin American Conference on Pattern Languages of Programming, Porto de Galinhas, PE, Brazil, August 2003. [6] Radoslav Menkyna. Towards combining aspect-oriented design patterns.In M´aria Bielikov´a, editor, Proc. Informatics and Information Technologies Student Research Conference, IIT.SRC 2007, pages 1–8, Bratislava,Slovakia, 2007. [7] Miles, R.: AspectJ Cookbook. O’Reilly, 2004. 33 [8] Bruno Dufour, Christopher Goard, Laurie Hendren, Oege de Moor, Ganesh Sittampalam, and Clark Verbrugge. 2004. Measuring the dynamic behaviour of AspectJ programs. In Proceedings of the 19th annual ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications (OOPSLA '04). با تشکر ؟ 34 • Lemos, O. A., Ferrari, F. C., Masiero, P. C., and Lopes, C. V. 2006. Testing aspect-oriented programming Pointcut Descriptors. In Proceedings of the 2nd Workshop on Testing Aspect-Oriented Programs (Portland, Maine, July 20 - 20, 2006). WTAOP '06. ACM, New York, NY, 33-38. DOI= http://doi.acm.org/10.1145/1146374.1146380 35

51,000 تومان