Poor Man’s LastFM History Downloader

I just wanted to warming up to C# and try WPF as a front. Also, LastFM may soon say goodbye (just a feeling) and I have good memories there that I want to keep. So, I built for myself this tiny desktop tool which can download recent tracks and artist scrobbles from LastFM’s API and saves into csv file. Maybe it will be useful for someone else.

Source: https://github.com/algunes/LastFM_HistoryDownloader

Posted in LastFMHistoryDownloader | Tagged , , , | Leave a comment

Aspect Oriented Programming Notes #4 – Proxy Mechanism

In a pure object-oriented sense we are calling a method of an object (Target object). That method has some code which is already in it. Aspect code has to run whenever we call this target method. How is it possible that some other code which is in some other class in some other method runs when we called this method, how is it even possible in a pure object-oriented paradigm.

It’s not actually possible. Aspect oriented programming is a completely different type of programming and what we do in Spring is we use some of the object oriented concepts to achieve aspect oriented programming. The way Spring uses these concepts is using a proxy.

We know proxy as a design pattern so what we do is instead of making a call to Class A, we make a call Class B and Class B internally makes a call to Class A but then it also adds some additional functionalities. This is something that Spring is doing behind the scenes for us.

Let’s try creating our own FactoryService class for having our own getBean() method:

public class FactoryService {
	public Object getBean(String beanType) {
		if(beanType.equals("Bicycle")) return new Bicycle();
		if(beanType.equals("Car")) return new Car();
		if(beanType.equals("Truck")) return new Truck();
		return null;

Instead of using the:

ApplicationContext ctx = new AnnotationConfigApplicationContext(SomeConfiguration.class);
SomeClass sc = (SomeClass) ctx.getBean("someClass");

we are going to create a FactoryService instance and use that to get a bean.

Continue reading
Posted in Spring Framework, Works | Tagged , , | Leave a comment

Aspect Oriented Programming Notes #3 – Some Additional Info

Reuse Aspect Pointcut Definitions

@Pointcut annotation is used for defining a pointcut independently to be reused in multiple advices.

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

public class ReuseCalculatorLoggingAspect {

	@Pointcut("execution(* *.*(..))")
	private void loggingOperation() {
	public void logBefore(JoinPoint joinPoint) {
	@AfterReturning(pointcut = "loggingOperation()", returning = "result")
	public void logAfterReturning(JoinPoint joinPoint, Object result) {
	@AfterThrowing(pointcut = "loggingOperation()",	throwing = "e")
	public void logAfterThrowing(JoinPoint joinPoint, IllegalArgumentException e) {

	public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
		return null;


Generally, if our pointcuts are shared between multiple aspects, it is better to centralize them in a common class. In this case, they must be declared as public. When we refer to this pointcut, we have to include the class name as well. If the class is not located in
the same package as the aspect, we have to include the package name also.

Continue reading
Posted in Spring Framework, Works | Tagged , , , , | Leave a comment

Aspect Oriented Programming Notes #2: Setting Up AOP Dependencies and Declaring Aspects, Advices, Pointcuts

An aspect is a Java class that modularizes a set of concerns (e.g., logging or transaction management) that cuts across multiple types and objects. Java classes that modularize such concerns are decorated with the @Aspect annotation. In AOP terminology, aspects are also complemented by advices, which in themselves have pointcuts.

An advice is a simple Java method with one of the advice annotations. AspectJ supports five types of advice annotations:

@Before, @After, @AfterReturning, @AfterThrowing, and @Around.

A pointcut is an expression that looks for types and objects on which to apply the aspect’s advices.

Spring 5 Recipes: A Problem-Solution Approach, Marten Deinum, Daniel Rubio, and Josh Long, APress Springer, 2017

For testing the aspects write a simple calculator interface like this:

public interface ArithmeticCalculator {

	public double add(double a, double b);
	public double sub(double a, double b);
	public double mul(double a, double b);
	public double div(double a, double b);


Then implementation of this interface:

Continue reading
Posted in Spring Framework, Works | Tagged , , , , , , , , , | Leave a comment

Aspect Oriented Programming Notes #1: The Concepts

Not just a feature that Spring provides, it’s a model of programming itself. (It’s functional programming)

When you writing in such languages you think of a problem and then you break it down into different functions. Each function accomplishes a particular unit of work. And then a function can call other functions and that’s how they talk to each other.

A single program consists of all these different functions and then you call each other and then when last function ends that’s when the program is complete.

This is the way you would think if you were to write code in a functional programming language. You think of them as different functions.

The problem is here is that if the complex design is involved then you would have a whole lot of function and independencies between functions things could get messy. Some situations you would get a better design if you’d use object oriented programming.

Here is a problem, not all of the task that you would want your program to do can be classified into objects.

Continue reading
Posted in Spring Framework, Uncategorized, Works | Tagged , , | Leave a comment

A Naive Example of Dependency Injection

–> It’s a way in which you decouple the conventional dependency relationships between objects.

Say we have two objects that are related to each other, one is dependent on the other. The idea is decouple this dependency. So that they’re not tied to each other.

Two Different Classes
Circle c = new Circle();

Triangle t = new Triangle();

We can use polymorphism:

Realization: Circle and Triangle implements Shape interface.
Shape s1 = new Circle();

Shape s2 = new Triangle();

Still tying the code to a triangle or a circle. It still hard coded to use either a triangle or a circle.

Continue reading
Posted in Spring Framework, Works | Tagged , | Leave a comment