Design Pattern zur Implementierung von Business Rules mit Hunderten von if else in Java

Habe ich die Umsetzung bestimmter Geschäftsregeln mit Hunderten von Zeilen code unten

if this
      then this
else if
      then this
.
. //hundreds of lines of rules
 else
      that

Haben wir keine design-Muster, die effektiv implementieren diese oder die Wiederverwendung von code, sodass Sie angewendet werden können, um alle unterschiedlichen Regeln.
Ich habe gehört, der Spezifikation Muster, das erzeugt so etwas wie unten

public interface Specification {

boolean isSatisfiedBy(Object o);

Specification and(Specification specification);

Specification or(Specification specification);

Specification not(Specification specification);
}


public abstract class AbstractSpecification implements Specification {

public abstract boolean isSatisfiedBy(Object o);

public Specification and(final Specification specification) {
 return new AndSpecification(this, specification);
}

public Specification or(final Specification specification) {
 return new OrSpecification(this, specification);
}

 public Specification not(final Specification specification) {
 return new NotSpecification(specification);
}
}

Und danach die Umsetzung Ist,Und -, Oder-Methoden, aber ich denke, dass diese nicht speichern, die mir schreiben, die if -, else(kann mein Verständnis falsch ist)...

Gibt es keinen besten Ansatz zur Umsetzung eines solchen business-Regeln, die so viele if else-Anweisungen?

EDIT : Nur ein Beispiel.A,B,C usw. sind Eigenschaften, die einer Klasse.Abgesehen von diesen gibt es ähnlich wie viele andere Regeln.Ich wnat, um einen generischen code für diese.

    If <A> = 'something' and <B> = something then
    If <C> = 02 and <D> <> 02 and < E> <> 02  then
        'something'
    Else if <H> <> 02 and <I> = 02 and <J> <> 02  then
        'something'
    Else if <H> <> 02 and <I> <> 02 and <J> = 02  then
        'something'
    Else if <H> <> 02 and <I> = 02 and <J> = 02  then 
        'something'
    Else if <H> = 02 and <I> = 02 and <J> <> 02  then 
        'something'
    Else if <H> = 02 and <I> <> 02 and <J> = 02  then 
        'something'
    Else if <H> = 02 and <I> = 02 and <J> = 02  then:
        If <Q> = Y then
            'something'
        Else then 
            'something'
Else :
Value of <Z>
Kommentar zu dem Problem - Öffnen
können Sie einige Beispiel von if-else-Anweisungen? wenn es irgendwelche ähnlichkeiten Kommentarautor: stinepike
Einsatz von state-Muster? Kommentarautor: Fendy
Ich denke, die "Chain of Responsibility"-Pattern genutzt werden könnte, hier: oodesign.com/chain-of-responsibility-pattern.html Kommentarautor: Marco Forberg

InformationsquelleAutor der Frage SCoder | 2013-05-31

Schreibe einen Kommentar