This document discusses aspect oriented programming (AOP) with Spring. It describes how AOP can be used to modularize cross-cutting concerns like logging and transaction management. It provides examples of implementing logging using both a naive approach and with AOP. It explains key AOP concepts like aspects, pointcuts, join points and advice. It also summarizes how AOP can be used with Spring through either the @AspectJ annotation style or XML schema-based style.
In this cheat sheet, you can find object oriented programming concept's fundamentals very easily. Some topics has very details explanations that could be very helpful those who is in entry level in java mostly object oriented world.
Contents :
Language Concepts
How Objective C works- Basics
Data Types
NSInteger
NSNumber
Operators
Loop
Inheritance
Method Overloading
Mutable and Immutable Strings
Mutable and Immutable Arrays
File Management
Object oriented programming with pythonArslan Arshad
A short intro to how Object Oriented Paradigm work in Python Programming language. This presentation created for beginner like bachelor student of Computer Science.
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAMaulik Borsaniya
Classes and Object-oriented Programming:
Classes: Creating a Class, The Self Variable, Constructor, Types of Variables, Namespaces, Types of Methods (Instance Methods, Class Methods, Static Methods), Passing Members of One Class to Another Class, Inner Classes
Inheritance and Polymorphism: Constructors in Inheritance, Overriding Super Class Constructors and Methods, The super() Method, Types of Inheritance, Single Inheritance, Multiple Inheritance, Method Resolution Order (MRO), Polymorphism, Duck Typing Philosophy of Python, Operator Overloading, Method Overloading, Method Overriding
Abstract Classes and Interfaces: Abstract Method and Abstract Class, Interfaces in Python, Abstract Classes vs. Interfaces,
In this cheat sheet, you can find object oriented programming concept's fundamentals very easily. Some topics has very details explanations that could be very helpful those who is in entry level in java mostly object oriented world.
Contents :
Language Concepts
How Objective C works- Basics
Data Types
NSInteger
NSNumber
Operators
Loop
Inheritance
Method Overloading
Mutable and Immutable Strings
Mutable and Immutable Arrays
File Management
Object oriented programming with pythonArslan Arshad
A short intro to how Object Oriented Paradigm work in Python Programming language. This presentation created for beginner like bachelor student of Computer Science.
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAMaulik Borsaniya
Classes and Object-oriented Programming:
Classes: Creating a Class, The Self Variable, Constructor, Types of Variables, Namespaces, Types of Methods (Instance Methods, Class Methods, Static Methods), Passing Members of One Class to Another Class, Inner Classes
Inheritance and Polymorphism: Constructors in Inheritance, Overriding Super Class Constructors and Methods, The super() Method, Types of Inheritance, Single Inheritance, Multiple Inheritance, Method Resolution Order (MRO), Polymorphism, Duck Typing Philosophy of Python, Operator Overloading, Method Overloading, Method Overriding
Abstract Classes and Interfaces: Abstract Method and Abstract Class, Interfaces in Python, Abstract Classes vs. Interfaces,
Aspect-oriented programming, or AOP, is a programming technique that allows programmers to modularize crosscutting concerns
It is often defined as a programming technique that promotes separation of crosscutting concerns with in a software system
concerns :
A concern is a particular issue, concept, or area of interest for an application: typically, a goal the application must meet
Introduction to AOP, AspectJ, and Explicit Join PointsKevin Hoffman
An introduction to and history of aspect-oriented programming. A short overview of AspectJ, certain challenges such as the state-point separation problem, and how explicit join points (EJPs) help mitigate these problems.
Ever heard of the Law of Demeter? How about the Liskov Substitution Principle? This talk introduces key object-oriented laws and principles currently used in our field and provides guidance for their use when building applications on the .NET platform.
Back-2-Basics: .NET Coding Standards For The Real World (2011)David McCarter
Revamped for 2011 (90% new material), this session will guide any level of programmer to greater productivity by providing the information needed to write consistent, maintainable code. Learn about project setup, assembly layout, code style, defensive programming and much, much more. Code tips are included to help you write better, error free applications. Lots of code examples in C# and VB.NET. This session is based off my latest book, David McCarter's .NET Coding Standards.
Daggerate your code - Write your own annotation processorBartosz Kosarzycki
Length: 30 min
Annotations have become a trendy topic in the Android community. Almost all automation & boiler-plate code elimination is done through annotations - starting from DTOs description (google.GSON), REST libraries (Retrofit) to dependency injection (google.Dagger2). But what if you want to eliminate boiler-plate code in your custom project? Or maybe you're writing a library for other Android-developers and you want to easily initialize that library with annotations.
This presentation walks you through the basic theory behind annotation processing and tells you how to write the most elemental annotation processor. Starting from annotation-search in the source code, source-code analysis and lastly source-code generation. The latter is done with the use of Square's JavaPoet library.
With Java 8 adoption skyrocketing, is Scala still relevant? In the opinion of this session’s speaker, the answer is an unequivocal yes. To make his point, he showcases practical examples where Scala's features provide a definitive advantage over Java 8. The session covers
• Effective logging with traits and by-name parameters
• Day to Day Type inference
• Pattern matching for fun and profit
• Type-safe easy generic Class<t> passing
• Concise third party enhancement
Hopefully you’ll leave the session with a better idea of the advantages Scala offers and perhaps a fresh outlook on software design.
In this lecture we look at the patterns in chapter 18 in the textbook (Patterns of Enterprise Application Architecture). The lecture is in two parts. First we go through each of the patterns and explain each.
Then in the second part we look at a problem we have to solve and try to get the patterns to show themselves at the time they are needed.
বাংলাদেশের অর্থনৈতিক সমীক্ষা ২০২৪ [Bangladesh Economic Review 2024 Bangla.pdf] কম্পিউটার , ট্যাব ও স্মার্ট ফোন ভার্সন সহ সম্পূর্ণ বাংলা ই-বুক বা pdf বই " সুচিপত্র ...বুকমার্ক মেনু 🔖 ও হাইপার লিংক মেনু 📝👆 যুক্ত ..
আমাদের সবার জন্য খুব খুব গুরুত্বপূর্ণ একটি বই ..বিসিএস, ব্যাংক, ইউনিভার্সিটি ভর্তি ও যে কোন প্রতিযোগিতা মূলক পরীক্ষার জন্য এর খুব ইম্পরট্যান্ট একটি বিষয় ...তাছাড়া বাংলাদেশের সাম্প্রতিক যে কোন ডাটা বা তথ্য এই বইতে পাবেন ...
তাই একজন নাগরিক হিসাবে এই তথ্য গুলো আপনার জানা প্রয়োজন ...।
বিসিএস ও ব্যাংক এর লিখিত পরীক্ষা ...+এছাড়া মাধ্যমিক ও উচ্চমাধ্যমিকের স্টুডেন্টদের জন্য অনেক কাজে আসবে ...
A review of the growth of the Israel Genealogy Research Association Database Collection for the last 12 months. Our collection is now passed the 3 million mark and still growing. See which archives have contributed the most. See the different types of records we have, and which years have had records added. You can also see what we have for the future.
Macroeconomics- Movie Location
This will be used as part of your Personal Professional Portfolio once graded.
Objective:
Prepare a presentation or a paper using research, basic comparative analysis, data organization and application of economic information. You will make an informed assessment of an economic climate outside of the United States to accomplish an entertainment industry objective.
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...Levi Shapiro
Letter from the Congress of the United States regarding Anti-Semitism sent June 3rd to MIT President Sally Kornbluth, MIT Corp Chair, Mark Gorenberg
Dear Dr. Kornbluth and Mr. Gorenberg,
The US House of Representatives is deeply concerned by ongoing and pervasive acts of antisemitic
harassment and intimidation at the Massachusetts Institute of Technology (MIT). Failing to act decisively to ensure a safe learning environment for all students would be a grave dereliction of your responsibilities as President of MIT and Chair of the MIT Corporation.
This Congress will not stand idly by and allow an environment hostile to Jewish students to persist. The House believes that your institution is in violation of Title VI of the Civil Rights Act, and the inability or
unwillingness to rectify this violation through action requires accountability.
Postsecondary education is a unique opportunity for students to learn and have their ideas and beliefs challenged. However, universities receiving hundreds of millions of federal funds annually have denied
students that opportunity and have been hijacked to become venues for the promotion of terrorism, antisemitic harassment and intimidation, unlawful encampments, and in some cases, assaults and riots.
The House of Representatives will not countenance the use of federal funds to indoctrinate students into hateful, antisemitic, anti-American supporters of terrorism. Investigations into campus antisemitism by the Committee on Education and the Workforce and the Committee on Ways and Means have been expanded into a Congress-wide probe across all relevant jurisdictions to address this national crisis. The undersigned Committees will conduct oversight into the use of federal funds at MIT and its learning environment under authorities granted to each Committee.
• The Committee on Education and the Workforce has been investigating your institution since December 7, 2023. The Committee has broad jurisdiction over postsecondary education, including its compliance with Title VI of the Civil Rights Act, campus safety concerns over disruptions to the learning environment, and the awarding of federal student aid under the Higher Education Act.
• The Committee on Oversight and Accountability is investigating the sources of funding and other support flowing to groups espousing pro-Hamas propaganda and engaged in antisemitic harassment and intimidation of students. The Committee on Oversight and Accountability is the principal oversight committee of the US House of Representatives and has broad authority to investigate “any matter” at “any time” under House Rule X.
• The Committee on Ways and Means has been investigating several universities since November 15, 2023, when the Committee held a hearing entitled From Ivory Towers to Dark Corners: Investigating the Nexus Between Antisemitism, Tax-Exempt Universities, and Terror Financing. The Committee followed the hearing with letters to those institutions on January 10, 202
Delivering Micro-Credentials in Technical and Vocational Education and TrainingAG2 Design
Explore how micro-credentials are transforming Technical and Vocational Education and Training (TVET) with this comprehensive slide deck. Discover what micro-credentials are, their importance in TVET, the advantages they offer, and the insights from industry experts. Additionally, learn about the top software applications available for creating and managing micro-credentials. This presentation also includes valuable resources and a discussion on the future of these specialised certifications.
For more detailed information on delivering micro-credentials in TVET, visit this https://tvettrainer.com/delivering-micro-credentials-in-tvet/
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...NelTorrente
In this research, it concludes that while the readiness of teachers in Caloocan City to implement the MATATAG Curriculum is generally positive, targeted efforts in professional development, resource distribution, support networks, and comprehensive preparation can address the existing gaps and ensure successful curriculum implementation.
Normal Labour/ Stages of Labour/ Mechanism of LabourWasim Ak
Normal labor is also termed spontaneous labor, defined as the natural physiological process through which the fetus, placenta, and membranes are expelled from the uterus through the birth canal at term (37 to 42 weeks
2. Problem area
• How to modularize concerns that span multiple classes
and layers?
• Examples of cross-cutting concerns:
– Transaction management
– Logging
– Profiling
– Security
– Internationalisation
3. Logging: A naive approach
public class HibernateEventDAO
{
Retrieving log p
private static Log log = LogFactory.getLog( HibernateEventDAO.class );
g g g yg g(
instance
public Integer saveEvent( Event event )
{
log.info( ”Executing saveEvent( Event ) with argument + ” event.toString() );
Logging method
executions Session session = sessionManager.getCurrentSession();
return (Integer) session.save( event );
}
public Event getEvent( Integer id )
{
log.info( ”Executing getEvent( int )” );
Session session = sessionManager.getCurrentSession();
return (Event) session.get( Event.class, id );
}
4. Logging: A naive approach
Invokes methods on
the DAOs
EventManager Service layer
(method invocation)
DAOs perform
both logging and
persistence
operations
PersonDAO EventDAO Persistence layer
5. Shortcomings of naive approach
• Mixes persistence and logging functionality
– Violates the principle of separation of concerns
– Increases complexity
• Involves repetition of code
– Violates the DRY principle
– Makes it difficult to change
• Couples the LogFactory to the HibernateEventDAO
– Prevents loosely coupled design
– Makes re-use and testing problematic
6. Logging: The AOP approach
EventManager Service layer
(method invocation)
Intercepts method
invocations and
performs logging
AOP interceptor
DAOs perform
persistence only
PersonDAO EventDAO Persistence layer
7. Advantages of AOP approach
• Separates persistence and logging functionality
– The logging concern taken care of by the interceptor
– Decreases complexity
• Promotes code reuse and modularization
– The AOP interceptor is used by all methods in the DAOs
– Makes it easier to change
• Decouples the LogFactory from the DAO impl’s
– The HibernateEventDAO is unaware of being logged
– Makes re-use and testing simple
8. Aspect Oriented Programming
• Definition: Enables encapsulation of functionality that
affects multiple classes in separate units
• Complements object oriented programming
• Most popular implementation for Java is AspectJ
– Aspect oriented extension for Java
– Available as Eclipse plugin and standalone IDE
10. AOP with Spring
• The AOP framework is a key component of Spring
• Ai
Aims at providing i t
t idi integration b t
ti between AOP and I C
d IoC
• Integrates – but doesn’t compete – with AspectJ
doesn t
• Provides two techniques for defining aspects:
– @AspectJ annotation
– XML schema-based
11. AOP concepts
• Aspect
– A concern that cuts across multiple classes and layers
• Join point
– A method invocation during t e e ecut o o a p og a
et od ocat o du g the execution of program
• Advice
– An implementation of a concern represented as an interceptor
• Pointcut
– An expression mapped to a join point
12. @AspectJ support
• Style of declaring aspects as regular Java classes with
Java 5 annotations
• R
Requires aspectjweaver and aspectjrt on th classpath
i tj d tj t the l th
• Enabled by including the following information in the
Spring configuration file:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<aop:aspectj-autoproxy/>
13. Declaring an aspect
• A concern that cuts across multiple classses and layers
@Aspect annotation import org.aspectj.lang.annotation.Aspect;
@Aspect
Any bean with a class
p
public class LoggingInterceptor
gg g p
annotated as an aspect
t t d t {
will be automatically // ...
detected by Spring }
Regular bean definition
pointing t a b
i ti to bean class
l <bean id="loggingInterceptor"
with the @Aspect class="no.uio.inf5750.interceptor.LoggingInterceptor"/>
annotation
14. Declaring a pointcut
• An expression mapped to a join point (method
invocation)
AspectJ pointcut expression that determines
which method executions to intercept
Indicated by the
@Pointcut
@P i t t annotation
t ti @Aspect
Public class LoggingInterceptor
{
@Pointcut( "execution( * no.uio.inf5750.dao.*.*(..) )" )
private void daoLayer() {}
Pointcut signature provided by
a regular method definition
15. Pointcut expression pattern
• The execution pointcut designator is used most often
Method name.
Pointcut Can use * to
Can use * to Exception type.
designator. match any type.
match any type. Optional.
Mandatory. Mandatory.
Mandatory.
designator( modifiers return-type declaring-type name(params) throws )
g ( yp g yp (p )
() = no params.
Package and
P k d
Public, private, (..) = any nr of params.
class name.
etc. Optional. (*,String) = one of any
Optional.
type, one of String.
16. Pointcut expression examples
Any public method execution( public * *(..) )
Any public method defined
execution( public * no.uio.inf5750.dao.*.*(..) )
in the dao package
Any method with a name
execution( * save*(..) )
beginning with save
Any method defined by the
execution( * no.uio.inf5750.dao.EventDAO.*(*) )
i ( i i f5750 d E DAO *(*)
EventDAO interface with one param
17. Declaring advice
• Implementation of concern represented as an interceptor
• Types
– Before advice
– After advice Provides access to the
current join point (target object,
– Around advice description of advised method, ect. )
d i ti f d i d th d t
@Aspect
Before advice. public class LoggingInterceptor
Executes before the {
@Before( ”no.uio.inf5750.interceptor.LoggingInterceptor.daoLayer()” )
matched method
method. public void intercept( JoinPoint joinPoint )
Declared using the {
@Before annotation. log.info( ”Executing ” + joinPoint.getSignature().toShortString() );
}
18. After returning & throwing advice
After returning advice. @Aspect
Executes after the public class LoggingInterceptor
matched method has {
@AfterReturning( ”no.uio.inf5750.interceptor.LoggingInterceptor.daoLayer()” )
returned normally.
normally public void i t
bli id intercept( J i P i t j i P i t )
t( JoinPoint joinPoint
Declared using the {
@AfterReturning log.info( ”Executed successfully ” + joinPoint.getSignature().toShortString() );
annotation. }
@Aspect
After throwing advice. public class LoggingInterceptor
Executes after the {
matched method has @AfterThrowing( ”no.uio.inf5750.interceptor.LoggingInterceptor.daoLayer()” )
thrown an exception. public void intercept( JoinPoint joinPoint )
Declared using {
log.info( ”Execution failed ” + joinPoint.getSignature().toShortString() );
@AfterThrowing.
}
19. Around advice
• Can do work both before and after the method executes
• Determines when, how and if the method is executed
@Aspect
public class LoggingInterceptor
{
@Around( ”
@A d( ”no.uio.inf5750.interceptor.LoggingInterceptor.daoLayer()” )
i i f5750 i t t L i I t t d L ()”
Around advice. public void intercept( ProceedingJoinPoint joinPoint )
{
The first parameter log.info( ”Executing ” + joinPoint.getSignature().toShortString() );
must be of type
ProceedingJoinPoint – try
{
calling proceed() causes joinPoint.proceed();
the target method to }
execute. catch ( Throwable t )
{
Declared using the log.error( t.getMessage() + ”: ” + joinPoint.getSignature().toShortString() );
@Around annotation. throw t;
}
log.info( ”Successfully executed ” + joinPoint.getSignature().toShortString() );
}
20. Accessing arguments
• The args binding form makes argument values available
to the advice body
• A
Argument name must correspond with advice method
t t d ith d i th d
signature
Makes the object @Aspect
argument available
g public class LoggingInterceptor
to the advice body {
@Before( ”no.uio.inf5750.interceptor.LoggingInterceptor.daoLayer() and ” +
”args( object, .. )” )
public void intercept( JoinPoint joinPoint, Object object )
{
log.info( ”Executing ” + joinPoint.getSignature().toShortString() +
Will restrict matching ” with argument ” + object.toString() );
to methods declaring }
at least one parameter
21. Accessing return values
• The returning binding form makes the return value
available to the advice body
• R t
Return value name must correspond with advice method
l t d ith d i th d
signature
Makes the object @Aspect
return value public class LoggingInterceptor
available to the {
advice body @AfterReturning(
pointcut=”no.uio.inf5750.interceptor.LoggingInterceptor.daoLayer() ”,
returning=”object” )
public void intercept( JoinPoint joinPoint, Object object )
{
Will restrict matching log.info( ”Executed ” + joinPoint.getSignature().toShortString() +
to methods returning a ” with return value ” + object.toString() );
}
value of specified type
22. Schema-based
Schema based support
• L t you d fi aspects using th aop namespace t
Lets define t i the tags
in the Spring configuration file
• Enabled by importing the Spring aop schema
• Pointcut expressions and advice types similar to
@AspectJ
• Suitable when:
– Y are unable to use J
You bl Java 5
– Prefer an XML based format
23. Declaring an aspect
• An aspect is a regular Java object defined as a bean in
the Spring context
All configuration inside
an <aop:config> element
<aop:config>
<aop:aspect id=”logging” ref=”loggingInterceptor”>
Aspect declared using
p g
the <aop:aspect> </aop:aspect>
element. Backing bean </aop:config>
is referenced
with the ref attribute.
<bean id="loggingInterceptor"
class="no.uio.inf5750.interceptor.LoggingInterceptor"/>
Regular bean definition
24. Declaring a pointcut
• Pointcut expressions are similar to @AspectJ
• A pointcut can be shared across advice
Pointcut declared inside
<aop:config> element
using the <aop:config>
<aop:pointcut> element
<aop:pointcut id=”daoLayer”
<aop pointc t id ”daoLa er”
expression="execution( * no.uio.inf5750.dao.*.*(..) )”/>
</aop:config>
Can also be defined
inside aspects
25. Declaring advice
Before advice. <aop:aspect id=”logging” ref=”loggingInterceptor”>
<aop:before pointcut-ref=”daoLayer” method=”intercept”/>
Declared inside an
aspect.
aspect </aop:aspect>
Refers to pointcut Refers to advising method
public class LoggingInterceptor
Advice is a regular {
Java class public void intercept( JoinPoint joinPoint )
{
// Do some useful intercepting work
}
}
27. AOP - Transaction Management
public i
bli interface T
f TransactionManager
i M
TransactionManager {
interface public void enter();
public void abort();
p
public void leave();
();
@Aspect
Transaction management public interface TransactionInterceptor
implemented with {
around advice @Around( ”execution( public no.uio.inf5750.dao.*.*(..) )” ) // In-line pointcut
public void intercept( ProceedingJoinPoint joinPoint )
{
transactionManager.enter();
g ();
Enters transaction
before method invocation try
{
joinPoint.proceed();
}
Aborts and rolls back catch ( Throwable t )
transaction if method fails {
transactionManager.abort();
throw t;
}
Leaves transaction if
method completes norm. transactionManager.leave();
28. @AspectJ or Schema based?
Schema-based?
• Advantages of schema style
– Can be used with any JDK level
– Clearer which aspects are present in the system
• Advantages of @AspectJ style
– One single unit where information is encapsulated for an aspect
– Possible to combine named pointcuts
– Can be understood by AspectJ – easy to migrate later
29. Summary
• Key components in AOP are aspect, pointcut, join point,
and advice
• AOP lets you encapsulate functionality that affects
multiple classes in an interceptor
• Advantages of AOP:
– Promotes separation of concern
– Promotes code reuse and modularization
– Promotes loosely coupled design
30. References
• The Spring reference documentation - Chapter 6
– www.springframework.org
• AOP example code
– www ifi uio no/INF5750/h07/undervisningsplan xml
www.ifi.uio.no/INF5750/h07/undervisningsplan.xml