<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FDesign_Pattern%2FChain_of_Responsibility_Patterns</id>
		<title>Java Tutorial/Design Pattern/Chain of Responsibility Patterns - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FDesign_Pattern%2FChain_of_Responsibility_Patterns"/>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_Tutorial/Design_Pattern/Chain_of_Responsibility_Patterns&amp;action=history"/>
		<updated>2026-04-09T01:01:41Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://jexp.ru/index.php?title=Java_Tutorial/Design_Pattern/Chain_of_Responsibility_Patterns&amp;diff=4458&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_Tutorial/Design_Pattern/Chain_of_Responsibility_Patterns&amp;diff=4458&amp;oldid=prev"/>
				<updated>2010-06-01T05:02:25Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 05:02, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://jexp.ru/index.php?title=Java_Tutorial/Design_Pattern/Chain_of_Responsibility_Patterns&amp;diff=4457&amp;oldid=prev</id>
		<title> в 17:44, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_Tutorial/Design_Pattern/Chain_of_Responsibility_Patterns&amp;diff=4457&amp;oldid=prev"/>
				<updated>2010-05-31T17:44:27Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==  Chain of responsibility ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
// Carries the result data and whether the strategy was successful:&lt;br /&gt;
class Document {&lt;br /&gt;
  public double[] data;&lt;br /&gt;
  public Document(double[] data) {&lt;br /&gt;
    this.data = data;&lt;br /&gt;
  }&lt;br /&gt;
  private boolean succeeded;&lt;br /&gt;
  public boolean isSuccessful() {&lt;br /&gt;
    return succeeded;&lt;br /&gt;
  }&lt;br /&gt;
  public void setSuccessful(boolean b) {&lt;br /&gt;
    succeeded = b;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
interface Format {&lt;br /&gt;
  Document doFormat(Document m);&lt;br /&gt;
}&lt;br /&gt;
class EnlargeFont implements Format {&lt;br /&gt;
  public Document doFormat(Document m) {&lt;br /&gt;
    System.out.println(&amp;quot;Trying EnlargeFont algorithm&amp;quot;);&lt;br /&gt;
    Document r = new Document(new double[] { 1.1, 2.2 }); // Dummy data&lt;br /&gt;
    r.setSuccessful(false);&lt;br /&gt;
    return r;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class ChangeColor implements Format {&lt;br /&gt;
  public Document doFormat(Document m) {&lt;br /&gt;
    System.out.println(&amp;quot;Trying ChangeColor algorithm&amp;quot;);&lt;br /&gt;
    Document r = new Document(new double[] { 3.3, 4.4 }); // Dummy data&lt;br /&gt;
    r.setSuccessful(false);&lt;br /&gt;
    return r;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class AddHeader implements Format {&lt;br /&gt;
  public Document doFormat(Document m) {&lt;br /&gt;
    System.out.println(&amp;quot;Trying AddHeader algorithm&amp;quot;);&lt;br /&gt;
    Document r = new Document(new double[] { 5.5, 6.6 }); // Dummy data&lt;br /&gt;
    r.setSuccessful(true);&lt;br /&gt;
    return r;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class AddFooter implements Format {&lt;br /&gt;
  public Document doFormat(Document m) {&lt;br /&gt;
    System.out.println(&amp;quot;Trying AddFooter algorithm&amp;quot;);&lt;br /&gt;
    Document r = new Document(new double[] { 5.5, 6.6 }); // Dummy data&lt;br /&gt;
    r.setSuccessful(true);&lt;br /&gt;
    return r;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class DocumentFormat {&lt;br /&gt;
  private static Format[] solutions = { new EnlargeFont(), new ChangeColor(), new AddHeader(),&lt;br /&gt;
      new AddFooter(), };&lt;br /&gt;
  public static Document solve(Document line) {&lt;br /&gt;
    Document r = line;&lt;br /&gt;
    for (int i = 0; i &amp;lt; solutions.length; i++) {&lt;br /&gt;
      r = solutions[i].doFormat(r);&lt;br /&gt;
      if (r.isSuccessful())&lt;br /&gt;
        return r;&lt;br /&gt;
    }&lt;br /&gt;
    throw new RuntimeException(&amp;quot;unsolved: &amp;quot; + line);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
public class ChainOfResposibilityDemo {&lt;br /&gt;
  public static void main(String args[]) {&lt;br /&gt;
    Document line = new Document(new double[] { 1.0, 2.0, 1.0, 2.0, -1.0, 3.0, 4.0, 5.0, 4.0 });&lt;br /&gt;
    System.out.println(((Document) DocumentFormat.solve(line)).data);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Multiple dispatching ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.util.Random;&lt;br /&gt;
class Result {&lt;br /&gt;
  private String name;&lt;br /&gt;
  private Result(String name) {&lt;br /&gt;
    this.name = name;&lt;br /&gt;
  }&lt;br /&gt;
  public final static Result LessThan = new Result(&amp;quot;Less than&amp;quot;), Equal = new Result(&amp;quot;equal&amp;quot;),&lt;br /&gt;
      GreaterThan = new Result(&amp;quot;Greater than&amp;quot;);&lt;br /&gt;
  public String toString() {&lt;br /&gt;
    return name;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
interface Number {&lt;br /&gt;
  Result compete(Number it);&lt;br /&gt;
  Result eval(One p);&lt;br /&gt;
  Result eval(Two s);&lt;br /&gt;
  Result eval(Three r);&lt;br /&gt;
}&lt;br /&gt;
class One implements Number {&lt;br /&gt;
  public Result compete(Number it) {&lt;br /&gt;
    return it.eval(this);&lt;br /&gt;
  }&lt;br /&gt;
  public Result eval(One p) {&lt;br /&gt;
    return Result.GreaterThan;&lt;br /&gt;
  }&lt;br /&gt;
  public Result eval(Two s) {&lt;br /&gt;
    return Result.LessThan;&lt;br /&gt;
  }&lt;br /&gt;
  public Result eval(Three r) {&lt;br /&gt;
    return Result.Equal;&lt;br /&gt;
  }&lt;br /&gt;
  public String toString() {&lt;br /&gt;
    return &amp;quot;One&amp;quot;;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class Two implements Number {&lt;br /&gt;
  public Result compete(Number it) {&lt;br /&gt;
    return it.eval(this);&lt;br /&gt;
  }&lt;br /&gt;
  public Result eval(One p) {&lt;br /&gt;
    return Result.Equal;&lt;br /&gt;
  }&lt;br /&gt;
  public Result eval(Two s) {&lt;br /&gt;
    return Result.GreaterThan;&lt;br /&gt;
  }&lt;br /&gt;
  public Result eval(Three r) {&lt;br /&gt;
    return Result.LessThan;&lt;br /&gt;
  }&lt;br /&gt;
  public String toString() {&lt;br /&gt;
    return &amp;quot;Two&amp;quot;;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class Three implements Number {&lt;br /&gt;
  public Result compete(Number it) {&lt;br /&gt;
    return it.eval(this);&lt;br /&gt;
  }&lt;br /&gt;
  public Result eval(One p) {&lt;br /&gt;
    return Result.LessThan;&lt;br /&gt;
  }&lt;br /&gt;
  public Result eval(Two s) {&lt;br /&gt;
    return Result.Equal;&lt;br /&gt;
  }&lt;br /&gt;
  public Result eval(Three r) {&lt;br /&gt;
    return Result.GreaterThan;&lt;br /&gt;
  }&lt;br /&gt;
  public String toString() {&lt;br /&gt;
    return &amp;quot;Three&amp;quot;;&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class NumberGenerator {&lt;br /&gt;
  private static Random rand = new Random();&lt;br /&gt;
  public static Number newItem() {&lt;br /&gt;
    switch (rand.nextInt(3)) {&lt;br /&gt;
    default:&lt;br /&gt;
    case 0:&lt;br /&gt;
      return new Two();&lt;br /&gt;
    case 1:&lt;br /&gt;
      return new One();&lt;br /&gt;
    case 2:&lt;br /&gt;
      return new Three();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class Compete {&lt;br /&gt;
  public static void match(Number a, Number b) {&lt;br /&gt;
    System.out.println(a + &amp;quot; &amp;quot; + a.rupete(b) + &amp;quot; vs. &amp;quot; + b);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
public class MultipleDispathDemo {&lt;br /&gt;
  public static void main(String args[]) {&lt;br /&gt;
    int SIZE = 20;&lt;br /&gt;
    for (int i = 0; i &amp;lt; SIZE; i++)&lt;br /&gt;
      Compete.match(NumberGenerator.newItem(), NumberGenerator.newItem());&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Watch What is Going On with the Chain of Responsibility Patterns ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String args[]) {&lt;br /&gt;
    Application app = new Application();&lt;br /&gt;
    IntermediateLayer intermediateLayer = new IntermediateLayer(app);&lt;br /&gt;
    FrontEnd frontEnd = new FrontEnd(intermediateLayer);&lt;br /&gt;
    frontEnd.getHelp(HelpType.GENERAL_HELP);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class HelpType {&lt;br /&gt;
  public final static int FRONT_END_HELP = 1;&lt;br /&gt;
  public final static int INTERMEDIATE_LAYER_HELP = 2;&lt;br /&gt;
  public final static int GENERAL_HELP = 3;&lt;br /&gt;
}&lt;br /&gt;
interface HelpInterface {&lt;br /&gt;
  public void getHelp(int helpConstant);&lt;br /&gt;
}&lt;br /&gt;
class IntermediateLayer implements HelpInterface {&lt;br /&gt;
  HelpInterface successor;&lt;br /&gt;
  public IntermediateLayer(HelpInterface s) {&lt;br /&gt;
    successor = s;&lt;br /&gt;
  }&lt;br /&gt;
  public void getHelp(int helpConstant) {&lt;br /&gt;
    if (helpConstant != HelpType.INTERMEDIATE_LAYER_HELP) {&lt;br /&gt;
      successor.getHelp(helpConstant);&lt;br /&gt;
    } else {&lt;br /&gt;
      System.out.println(&amp;quot;intermediate&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class FrontEnd implements HelpInterface {&lt;br /&gt;
  HelpInterface successor;&lt;br /&gt;
  public FrontEnd(HelpInterface s) {&lt;br /&gt;
    successor = s;&lt;br /&gt;
  }&lt;br /&gt;
  public void getHelp(int helpConstant) {&lt;br /&gt;
    if (helpConstant != HelpType.FRONT_END_HELP) {&lt;br /&gt;
      successor.getHelp(helpConstant);&lt;br /&gt;
    } else {&lt;br /&gt;
      System.out.println(&amp;quot;front end&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class Application implements HelpInterface {&lt;br /&gt;
  public void getHelp(int helpConstant) {&lt;br /&gt;
    System.out.println(&amp;quot;application&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>