Kicsit tobb errol is:
Kicsit tobb errol is:
Elgondolkoztam azon, hogy igazabol olyan hu de sok design pattern-t nem hasznalok meg ense. Aki mar vagy 5 eve kodol androidban. Olyan 6-7-et maximum. (tobb hirtelen nem is jut eszembe)
Nezzuk mik ezek:
public static class BeanPattern {
String name;
int yearsold;
public BeanPattern(String name, int yearsold) {
this.name = name;
this.yearsold = yearsold;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getYearsOld() {
return yearsold;
}
public void setYearsOld(int yearsold) {
this.yearsold = yearsold;
}
@Override
public String toString() {
return name + " : " + yearsold;
}
}
public static class InstancePattern {
private static InstancePattern instance = new InstancePattern();
private InstancePattern() {}
public static InstancePattern getInstance() {
return instance;
}
@Override
public String toString() {
return "InstancePattern";
}
}
public static class ObserverPattern {
public static interface ObserverPatternListener {
public void doSomething(int value);
}
private ObserverPatternListener mListener;
public ObserverPatternListener getListener() {
return mListener;
}
public void setListener(ObserverPatternListener mListener) {
this.mListener = mListener;
}
}
public abstract static class FactoryPattern {
public enum CLASSES { SECOND, THIRD }
interface IFirst {
public void asd1();
public void asd2(String value);
}
private FactoryPattern() {}
public static abstract class First implements IFirst {
protected abstract void Method1();
@Override
public void asd1() {
System.out.println("asd1");
}
@Override
public void asd2(String value) {
System.out.println("asd2" + value);
}
@Override
public String toString() {
return getClass().getSimpleName();
}
}
public static class Second extends First {
@Override
public String toString() {
return getClass().getSimpleName();
}
@Override
protected void Method1() {
}
}
public static class Third extends Second {
@Override
public String toString() {
return getClass().getSimpleName();
}
}
public static IFirst create(CLASSES classes) {
switch (classes) {
case SECOND:
return new Second();
case THIRD:
return new Third();
default:
break;
}
return null;
}
}
Builder, Facades.
Es vegul a temaban kezdoknek egy kisebb video (szerintem nagyon jol elmagyarazza a dolgokat):