You have a privilege to create a quiz (QnA) related to this subject and obtain creativity score...
OOP versus Aspect-Oriented and Functional Programming
The greatest scientist of all times, Archimedes, defined our world as a sequence of events.
Another famous Greek, Democritus, insisted that the world consists of matter objects, with the smallest called atoms.
Sounds like an argument between functional and object-oriented approach, right?
Object-Oriented Programming (OOP) focuses on objects. OO programmer spends time modeling a development task in objects, which have similar structure and behavior. This upfront planning is a significant part of OO design. Miscalculations in initial analysis can cause great problems in implementation.
Yes, OOP has its trade-offs.
Strong data typing allows compiler to prevent run-time crashes due type mismatch. That is good! But apparently not always. There are cases when developers prefer “generics”.
With all due respect to objects, there are common concerns, such as security, that go across many objects. There are common aspects, such as querying databases, which can be more efficiently expressed by non-OOP languages. Of course, Object-Relational Mapping (ORM) is kind of solving this problem. But ORM requires resources and slows down performance.
Creating objects is expensive! And although memory and disk space is almost free, these limitations might be significant for mobile and micro devices.
Overall OOP makes sense as a well-known development paradigm, understood and helpful in teamwork, which saves expenses on the most expensive factor of development, developers!
OOP is the mainstream of development, but it is not the only way of thinking.
Aspect-Oriented Programming
Aspect-Oriented Programming (AOP) complements Object-Oriented Programming focusing on common aspects. Not a class, but an aspect or a concern is the key unit in AOP. Transaction management can serve as an example of a crosscutting aspect for multiple types and objects.
The ideas of AOP can be expressed with its own language, such as AspectJ, or implemented in Java, for example, by the Spring framework.
*AOP has its own vocabulary that is commonly used in AspectJ and Spring:
Aspect: a concern that cuts across multiple classes. In Spring AOP, aspects are implemented with regular (the schema-based approach) or annotated classes (the @AspectJ style).
Join point: a point during the execution of a program, such as the execution of a method or the handling of an exception. In Spring AOP, a join point always represents a method execution.
Advice: action taken by an aspect at a particular join point. Different types of advice include "around," "before" and "after" advice. (Advice types are discussed below.) Many AOP frameworks, including Spring, model an advice as an interceptor, maintaining a chain of interceptors around the join point. A similar model is in Jva Servlet Filters, the methods, which can be called before or after the Servlet invocation.
Pointcut: a predicate that matches join points. Advice is associated with a pointcut expression and runs at any join point matched by the pointcut (for example, the execution of a method with a certain name). The concept of join points as matched by pointcut expressions is central to AOP, and Spring uses the AspectJ pointcut expression language by default.
Was it clear so far?
Introduction: declaring additional methods or fields on behalf of a type. Spring AOP allows you to introduce new interfaces (and a corresponding implementation) to any advised object. For example, you could use an introduction to make a bean implement an IsModified interface, to simplify caching. (An introduction is known as an inter-type declaration in the AspectJ community.)
Target object: object being advised by one or more aspects. Also referred to as the advised object. Since Spring AOP is implemented using runtime proxies, this object will always be a proxied object.
AOP proxy: an object created by the AOP framework in order to implement the aspect contracts (advise method executions and so on). In the Spring Framework, an AOP proxy will be a JDK dynamic proxy or a CGLIB proxy.
Weaving: linking aspects with other application types or objects to create an advised object. This can be done at compile time (using the AspectJ compiler, for example), load time, or at runtime. Spring AOP, like other pure Java AOP frameworks, performs weaving at runtime.
*Read a complete Spring AOP Reference: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html
Functional Programming Another complementary way of programming is functional programming.
Functional programming (FP) makes it easier to write parallel code for multiprocessors. Instead of mutable variables and loops FP provides powerful ways defining and composing functions.
The best example of FP implementation can be Scala, the language that combines functional and object-oriented programming. Scala works with Java and its tools and is used in many open source projects and companies. Twitter, LinkedIn, Foursquare, Tumblr, and more popular web sites are programmed with Scala.
This is a simple code sample that in three lines will reverse the sequence of words and sequence of characters in the words.
1. Check an example of Spring AOP CustomerService: http://www.mkyong.com/spring/spring-aop-examples-advice/
2. Read more about Scala in the Tutorial: http://docs.scala-lang.org/tutorials/scala-for-java-programmers.html
3. Create 2 QnA related to the AOP and 2 QnA for Functional Programming section, each with the following format where the first answer is correct and two other answers are wrong.
Question:
Answer:
Answer:
Answer:
1. Check an example of Spring AOP CustomerService: http://www.mkyong.com/spring/spring-aop-examples-advice/
2. Read more about Scala in the Tutorial: http://docs.scala-lang.org/tutorials/scala-for-java-programmers.html
3. Create 2 QnA related to the AOP and 2 QnA for Functional Programming section, each with the following format where the first answer is correct and two other answers are wrong.
Question:
Answer:
Answer:
Answer: