i had posted some stuff on AOP but got no response. so i thought of posting a blog on the topic.
this article in javaworld was one of the references for this blog. also referred to an article on aspectj on developerworks.
"aspect oriented programming (aop) is a new programming technique that allows programmers to modularize crosscutting concerns". crosscutting concerns is the keyword. in oops code is divided into classes. some common functionality which forms a part of many classes constitutes a crosscutting concern. take for example logging. other uses suggested are error-handling and authentication.
generally within each method of a class some logging code would be added.like logger.entry("msg:xx"); this messes the entire app. in aop it is possible to seperate such code. the app is written without any logging code. then "aspects" are added in seperately. within an aspect you define common code. that code can be inserted at different places within the app. these places are known as pointcuts. some include before a method execution, before a return type is given. many pointcuts are provided which allow you to insert aop code in most thinkable regions. what code is inserted is known as advice. so advices are the actual operations executed at a pointcut. the logging code can be included once in the advice, and pointcuts placed at different parts of the app.
aspectj is one aop implementation, part of the eclipse.org project. javaassist part of jboss is another one. javaassist performs aop in some other style.
aspectj can work on class files. no need for java files. same for javaassist. they make use of reflection to analyse a class and then inject aop code. now i am not sure how this works but i'll go on with what i have understood so far.
"Attributes are used for several defined purposes in the java class format, including the already-mentioned bytecode, constant values for fields, exception handling, and debugging infomation. .. From the beginning, the JVm spec has required JVMs to ignore attributes of unknown types. This requirement gives flexibility for extending the use of attributes to serve other purposes in the future, such as providing meta-information needed by frameworks that work with user classes" - an excerpt from developerworks. so aop compilers must be adding such attributes which can be used to effect aspects at runtime.
do attributes in .net (metadata in java) perform the same operation. only that the vm must be knowing the meanings of these attributes compared to the aop compiler incase of aop. also does the @Remote attribute in .net, cause an attribute to be included into the code, or does it cause the equivalent IL to be include. simply put, are attributes compile time or runtime. why i am asking is incase there is a custom attribute and the vm does not (by a miracle) get the implementation, does it ignore it. this would be a major runtime problem. also if at runtime wouldn't this slow the VM? somehow i feel the vm does these things, but how without sucking in performance?
which brings me to a second question. what do you think of intellectual property in java/c#. it is very easy to reverse engineer code. if not, simply aop some part. some applns like bcel and javaassist allow to modify bytecode and save the class file or modify the class file at runtime and use it dynamically.
No comments:
Post a Comment