Skip to content

Instantly share code, notes, and snippets.

class LikeButton {
public void onClick() {
System.out.println("Like the post");
}
}
@anshupitlia
anshupitlia / Main.java
Created June 9, 2020 12:48
Main Class
public class Main {
public static void main(String[] args) {
LikeButton likeButton = new LikeButton();
likeButton.onClick(); //Like the post
}
}
public class LikeButton {
private Reactions selectedReaction;
public void setSelectedReaction(Reactions selectedReaction) {
this.selectedReaction = selectedReaction;
}
LikeButton() {
selectedReaction = Reactions.LIKE;
}
@anshupitlia
anshupitlia / LikeButton.java
Created June 9, 2020 12:52
Like Button hover
public class LikeButton {
...
private Reactions hoveredReaction;
public void setHoveredReaction(Reactions hoveredReaction) {
this.hoveredReaction = hoveredReaction;
}
...
public void onHover() {
if (hoveredReaction == Reactions.LIKE) {
public interface Reaction {
void click();
void hover();
}
public class Haha implements Reaction {
public void onClick() {
System.out.println("Show Haha emoji");
}
public void onHover() {
System.out.println("Haha");
public class ClapButton {
private int clapCount;
void onClick() {
if (clapCount < 50) {
clapCount += 1; //shorthand notation for adding 1 clap
System.out.println("You clapped!");
}
else {
System.out.println("no impact");
}
public interface ClapInterface {
void onClick();
}
public class Below50 implements ClapInterface {
@Override
public void onClick() {
System.out.println("You clapped!");
}
}
public class Above50 implements ClapInterface {