I'll try to explain the topic according to my motto --"No bullshit , Just Code.."
1) SAM= Single Abstract Method = An Interface with Only One Method = Functional Interface
2) A class with a method which will consume a lambda expression
3) Now.. Actionnn...Lambda expression as a parameter
Okeyy... I know some of you need bullshit also :)
If you want to pass a behavior to a parameter (behavior= function=action) just create an interface and annotate it @FunctionalInterface and use Lambda Syntax like i did in above.
(param1,param2,,,,,paramN) -> {play with params}
Java 8 lots of built in @FunctionalInterface inside it. You can use them anywhere you need. Just google for them .
Bye
Thursday, February 9, 2017
Wednesday, February 8, 2017
Adapter Pattern VS Decorator Patter VS Facade Pattern VS Proxy Pattern VS Bridge Pattern - Summary - Table

Whatever...
Above is a list of Structural Design Patterns.
All of them is encapsulates some objects or interfaces and delegates the calls to them at the bottom .
So what is difference between them on top of their behaviour ?
The difference is your intent !

Just encapsulate and delegate. --From "The Joy of Painting"
Friday, January 6, 2017
Favor object composition over class inheritance in Java with Project Lombok Delegate annotation
Subject: Object composition in Java via Lombok @Delegate annotation
Problem Statement : One common drawback of using composition instead of inheritance is that methods being provided by individual components may have to be implemented in the derived type, even if they are only forwarding methods. In contrast, inheritance does not require all of the base class's methods to be re-implemented within the derived class. Rather, the derived class only need to implement (override) the methods having different behavior than the base class methods. This can require significantly less programming effort if the base class contains many methods providing default behavior and only a few of them need to be overridden within the derived class.
Solution: This drawback can be avoided by using traits, mixins, or protocol extensions. Some languages, such as Perl 6, provide a handles keyword to facilitate method forwarding. In Java, Project Lombok lets you implement delegation using a single @Delegate annotation on the field instead of copying and maintaining names and types of all methods from the delegated field
Code : For the ones who says - "No bullshit , just the code..." :))
import lombok.Data;
@Data
public class BasicStudent {
private String name;
public void writeYourNameOnTheBlackBoard (){
System.out.println ("There is no He/she/it in turkish because we are not sexists :) ");
}
}
import lombok.experimental.Delegate;
public class EnhancedStudent {
@Delegate
BasicStudent beaFeaturesCameHereWithAnnotation;
}
public class StudentProcessor {
public static void main (String[] args) {
EnhancedStudent enhancedStudent = new EnhancedStudent ();
enhancedStudent.writeYourNameOnTheBlackBoard ();
}
}
-- for the memory of Christoph Portman
Tuesday, January 3, 2017
Java Maze solver program
Copy , paste, run...
The ones are the walls in the below matrix and zeroes are open ways in the labyrinth.
We are trying to find shortest path to the given destination : which is (x,y)-> (19,8) here in the example
Just modify the maze by playing with the Ones and Zeroes and run it in your local
Subscribe to:
Posts (Atom)