docs/DesignPatterns

changeset 7:20c0116dcb97

added files (forgot for last commit
author meillo@marmaro.de
date Mon, 18 Jun 2007 12:10:45 +0200
parents 7744082fd6a3
children c9e5dcd79aae
files code/composite-component.java code/composite-icomponent.java code/composite-leaf.java code/composite-main.java composite.tex pics/composite.png pics/composite_big.png pics/observer_big.png
diffstat 8 files changed, 226 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/code/composite-component.java	Mon Jun 18 12:10:45 2007 +0200
     1.3 @@ -0,0 +1,34 @@
     1.4 +    class Composite implements IComponent {
     1.5 +            private String id;
     1.6 +            private List<IComponent> list = new ArrayList<IComponent> ();
     1.7 +
     1.8 +            public Composite(String id) {
     1.9 +                    this.id = id;
    1.10 +            }
    1.11 +
    1.12 +            public String toString() {
    1.13 +                    StringBuilder buf = new StringBuilder();
    1.14 +                    buf.append(String.format("(%s:", id));
    1.15 +
    1.16 +                    for (IComponent child : list) {
    1.17 +                          buf.append(" " + child.toString());
    1.18 +                    }
    1.19 +                    buf.append(")");
    1.20 +
    1.21 +                    return buf.toString();
    1.22 +            }
    1.23 +
    1.24 +            //public List<IComponent> getChildren()
    1.25 +
    1.26 +            public Collection getChildren(){
    1.27 +                    return list;
    1.28 +            }
    1.29 +
    1.30 +            public boolean addComponent(IComponent c){
    1.31 +                    return list.add(c);
    1.32 +            }
    1.33 +
    1.34 +            public boolean removeComponent(IComponent c){
    1.35 +                    return list.remove(c);
    1.36 +            }
    1.37 +    }
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/code/composite-icomponent.java	Mon Jun 18 12:10:45 2007 +0200
     2.3 @@ -0,0 +1,5 @@
     2.4 +    interface IComponent {
     2.5 +            Collection getChildren();
     2.6 +            boolean addComponent(IComponent c);     
     2.7 +            boolean removeComponent(IComponent c);
     2.8 +    }
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/code/composite-leaf.java	Mon Jun 18 12:10:45 2007 +0200
     3.3 @@ -0,0 +1,25 @@
     3.4 +    class Leaf implements IComponent {
     3.5 +            private String id;
     3.6 +
     3.7 +            public Leaf(String id) {
     3.8 +                    this.id = id;
     3.9 +            }
    3.10 +
    3.11 +            public String toString() {
    3.12 +                    return this.id;
    3.13 +            }
    3.14 +
    3.15 +            public Collection getChildren() {
    3.16 +                    return null;
    3.17 +            }
    3.18 +
    3.19 +            // false because failed to add
    3.20 +            public boolean addComponent(IComponent c) {
    3.21 +                    return false;
    3.22 +            }
    3.23 +
    3.24 +            // false because failed to find it for removal
    3.25 +            public boolean removeComponent(IComponent c) {
    3.26 +                    return false;
    3.27 +            }
    3.28 +    }
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/code/composite-main.java	Mon Jun 18 12:10:45 2007 +0200
     4.3 @@ -0,0 +1,19 @@
     4.4 +    public class Main {
     4.5 +            public static void main(String[] args) {
     4.6 +                    Composite england = new Composite("England");
     4.7 +                    Leaf york = new Leaf("York");
     4.8 +                    Leaf london = new Leaf("London");
     4.9 +                    england.addComponent(york);
    4.10 +                    england.addComponent(london);
    4.11 +                    england.removeComponent(york);
    4.12 +
    4.13 +                    Composite france = new Composite("France");
    4.14 +                    france.addComponent(new Leaf("Paris"));
    4.15 +
    4.16 +                    Composite europe = new Composite("Europe");
    4.17 +                    europe.addComponent(england);
    4.18 +                    europe.addComponent(france);
    4.19 +
    4.20 +                    System.out.println(europe.toString());
    4.21 +            }
    4.22 +    }
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/composite.tex	Mon Jun 18 12:10:45 2007 +0200
     5.3 @@ -0,0 +1,143 @@
     5.4 +% @file
     5.5 +% @brief   Referat DesignPattern `Composite'
     5.6 +% @author  dimitar dimitrov
     5.7 +% @since   2007-06-18
     5.8 +
     5.9 +
    5.10 +\documentclass{beamer}
    5.11 +
    5.12 +
    5.13 +  \usepackage[T1]{fontenc}
    5.14 +  \usepackage[latin1]{inputenc}
    5.15 +  \usepackage{ngerman}
    5.16 +  \usepackage{graphicx}
    5.17 +  \usepackage[automark]{scrpage2}
    5.18 +  \usepackage{listings}
    5.19 +  \input{Style01}
    5.20 +
    5.21 +
    5.22 +
    5.23 +\begin{document}
    5.24 +
    5.25 +
    5.26 +\title{Design Pattern ``Composite''}
    5.27 +\date{\today}
    5.28 +
    5.29 +\author{Dimitar Dimitrov}
    5.30 +
    5.31 +%\titlegraphic{\includegraphics[width=3cm]{Pics/Maka-Logo.png}}
    5.32 +
    5.33 +\frame{
    5.34 +  \titlepage
    5.35 +}
    5.36 +
    5.37 +
    5.38 +
    5.39 +
    5.40 +
    5.41 +\section[Outline]{}
    5.42 +\frame{
    5.43 +  Dauer der Präsentation: etwa 10 Minuten
    5.44 +  \vspace{2ex}
    5.45 +
    5.46 +  \tableofcontents
    5.47 +}
    5.48 +
    5.49 +
    5.50 +
    5.51 +
    5.52 +\section{Definition}
    5.53 +
    5.54 +\frame{ \frametitle{Definition}
    5.55 +
    5.56 +  \begin{block}{}
    5.57 +  \end{block}
    5.58 +
    5.59 +}
    5.60 +
    5.61 +
    5.62 +\section{Motivation}
    5.63 +
    5.64 +\frame{ \frametitle{Motivation}
    5.65 +
    5.66 +  \begin{block}{}
    5.67 +  \end{block}
    5.68 +
    5.69 +}
    5.70 +
    5.71 +
    5.72 +\section{Wann verwenden?}
    5.73 +\frame{ \frametitle{Wann verwenden?}
    5.74 +
    5.75 +  \begin{block}{}
    5.76 +  \end{block}
    5.77 +
    5.78 +}
    5.79 +
    5.80 +
    5.81 +
    5.82 +\section{Struktur}
    5.83 +
    5.84 +\frame{ \frametitle{UML-Diagramm des Composite-Pattern}
    5.85 +  \centerline{ \includegraphics[width=20em]{pics/composite_big.png} }
    5.86 +}
    5.87 +
    5.88 +
    5.89 +
    5.90 +
    5.91 +
    5.92 +\section{Java-Beispiel}
    5.93 +\frame{ \frametitle{class Main, interface IComponent}
    5.94 +
    5.95 +  {\tiny
    5.96 +    \lstinputlisting[language=java]{code/composite-main.java}
    5.97 +    \lstinputlisting[language=java]{code/composite-icomponent.java}
    5.98 +  }
    5.99 +
   5.100 +}
   5.101 +
   5.102 +
   5.103 +\frame{ \frametitle{class Composite}
   5.104 +
   5.105 +  {\tiny
   5.106 +    \lstinputlisting[language=java]{code/composite-composite.java}
   5.107 +  }
   5.108 +
   5.109 +}
   5.110 +
   5.111 +
   5.112 +\frame{ \frametitle{class Leaf}
   5.113 +
   5.114 +  {\tiny
   5.115 +    \lstinputlisting[language=java]{code/composite-leaf.java}
   5.116 +  }
   5.117 +
   5.118 +}
   5.119 +
   5.120 +
   5.121 +
   5.122 +
   5.123 +\section{Zusammenfassung}
   5.124 +\frame{ %\frametitle{Zusammenfassend}
   5.125 +  \begin{block}{Zusammenfassung}
   5.126 +  \begin{itemize}
   5.127 +    \item 
   5.128 +    \item 
   5.129 +    \item 
   5.130 +  \end{itemize}
   5.131 +  \end{block}
   5.132 +
   5.133 +  \pause
   5.134 +
   5.135 +  \begin{block}{Fazit}
   5.136 +    \begin{itemize}
   5.137 +      \item 
   5.138 +      \item 
   5.139 +      \item 
   5.140 +    \end{itemize}
   5.141 +  \end{block}
   5.142 +}
   5.143 +
   5.144 +
   5.145 +
   5.146 +\end{document}
     6.1 Binary file pics/composite.png has changed
     7.1 Binary file pics/composite_big.png has changed
     8.1 Binary file pics/observer_big.png has changed