Software Architecture VO/KU (707.023/707.024)

Implementation View

Denis Helic

IWM, TU Graz

Implementation View (1)

Implementation View (2)

Components in implementation architecture (1)

Components in implementation architecture (2)

Components in implementation architecture (3)

Component stereotypes in implementation view

(fig. from Reekie book)

Connectors in implementation architecture (1)

Connectors in implementation architecture (2)

Connectors in implementation architecture (3)

Connector styles (fig. from Reekie book)

Connectors in implementation architecture (4)

Implementation architecture: Example

Web server (fig. from Reekie book)

Conceptual vs. Implementation

ElementConceptualImplementation
ComponentsDomain-level responsibilitiesImplementation module
ConnectorsInformation flow"Uses" relationship
ViewsSingleSplit

Conceptual vs. Execution vs. Implementation

Component relations (Fig. from Reekie book)

Implementation architecture design

  1. Find application components
  2. Find infrastructure components
  3. Interface design
  4. Behavoir design and verification

Application components (1)

Application components (2)

Infrastructure components (1)

MPS: Infrastructure components (1)

MPS: Infrastructure components (2)


public class SomeServlet extends HttpServlet {
  public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {
    // Use "request" to read incoming HTTP headers (e.g. cookies)
    // and HTML form data (e.g. data the user entered and submitted)
    // Use "response" to specify the HTTP response line and headers
    // (e.g. specifying the content type, setting cookies).
    PrintWriter out = response.getWriter();
    // Use "out" to send content to browser
  }
}

MPS: Infrastructure components (3)

Interface design (1)

MPS: Interface design (1)

MPS: Interface design (2)

MPS: Interface design (3)

Behavior design

MPS: Implementation Architecture (1)

MPS: Implementation Architecture (2)

MPS: Interface Sequence Diagram

Non-runtime quality attributes

Impact-maps

Prototype

Implemention Example: MPS

Implementation

MPS design (1)

MPS: state machine (configuration system)

State/Choice01
Initial-11
ToolSelection2-
ToolParameters0-

MPS design (2)

MPS design (3)

MPS design (4)

MPS: class diagram (1)

MPS: class diagram (2)

MPS: class diagram (3)

MPS: class diagram (4)

MPS: class diagram (5)

MPS: Application execute


if(!isFinalState()) {
  State current_state = getCurrentState();
  if(current_state.execute(answers)) {
    state_number_ = transition_[state_number_]
      [current_state.getChoice()];
    ...
  } else {
    current_state.displayErrorMessage(panel);
  }
  panel.showPanel();
}

MPS: Application subclasses


protected void init(Map<String, String> parameters) {
  states_ = new State[4];
  states_[0] = new InitialState();
  states_[1] = new ToolSelectionState(cf_path + "config.txt");
  states_[2] = new ToolParametrizationState(cf_path + "config.txt");
  transition_ = new int[3][2];
  transition_[0][0] = -1;
  transition_[0][1] = 1;
  transition_[1][0] = 2;
  transition_[2][0] = 0;
  ...
}

MPS: State execute


final public boolean execute(List<Answer> answers) {
  setAnswers(answers);
  if(!areAnswersCorrect()) {
    return false;
  }
  processActionAnswers();
  processChoiceAnswers();
  return true;
}

MPS: Checking answers


private boolean areAnswersCorrect() {
  for(Question question : questions_) {
    if(!question.isAnswerCorrect()) {
       return false;
    }
  }
  return true;
}

MPS: Questions


public Question(String question, AnswerChecker checker) {
  this(question);
  checker_ = checker;
}

public boolean isAnswerCorrect() {
  if(checker_ != null) {
     return checker_.isAnswerCorrect(answer_.toString());
  }
  return true;
}

MPS: Questions (OC Principle)


public class NonEmptyAnswerChecker implements AnswerChecker {
  public String getErrorMessage() {
    return "Answer can not be empty";
  }
  public boolean isAnswerCorrect(String answer) {
    if((answer == null) || (answer.length() == 0)) {
      return false;
    }
    return true;
  }
}

MPS: State subclasses


protected void makeQuestions() {
  List<String> tools = new ArrayList<String>();
  tools.add("Wiki");
  tools.add("Blog");
  ..
}
protected void processChoiceAnswers() {
  choice_ = 0;
}
protected void processActionAnswers() {        
  Answer answer = questions_.get(0).getAnswer();
  WriteConfigFileAction action = new WriteConfigFileAction(path_, 
    answer.toString() + ":\n");
  action.executeAction();
}

MPS: Actions (new thread)


public abstract class Action implements Runnable {
  private boolean started_ = false;
  public void executeAction() {
    start();
  }
  private void start() {
    if(!started_) {
      started_ = true;
      Thread thread = new Thread(this);
      thread.start();
    }
  }
  public void run() {
    execute();
  }
  abstract protected void execute();
}

MPS: Action subclasses


protected void execute() {
  try {
    FileWriter writer = new FileWriter(path_, true);
    writer.write(message_);
    writer.flush();
    writer.close();
  } catch (IOException exc) {
    exc.printStackTrace();
    throw new RuntimeException(exc);
  }
}

MPS: Complete code

MPS Source code

Implementation Example End

Implementation arch. summary

What you need to submit:

  1. Detailed implementation architecture with app, infrastructure and interfaces
  2. Sequence diagram of application interfaces

Prototype summary

What you need to submit:

  1. Class diagrams
  2. Sequence diagrams
  3. Code

Model-View-Controller (1)

Model-View-Controller (2)

Model-View-Controller (3)

img/mvc_arch.png

Model-View-Controller (4)

Model-View-Controller (5)

Model-View-Controller (6)

img/model.png

Model-View-Controller (7)

Model-View-Controller (8)

Model-View-Controller (9)

img/uodb_mvc_arch.png

IA 1: Observer Pattern (1)

img/mvc_observer_arch.png

IA 1: Observer Pattern (2)

IA 1: Observer Pattern (3)

MVC: An example with Observer pattern (1)

MVC: An example with Observer pattern (2)

MVC: An example with Observer pattern (3)

final public class SimpleModel extends Observable {
...
 public void setValue(int value) {
  if ((value > 100) || (value < 0)) {
   throw new IllegalArgumentException("The value must be ..");
  }
  value_ = value;
  setChanged();
  notifyObservers();
 }
...
}

Source code

MVC: An example with Observer pattern (4)

MVC: An example with Observer pattern (5)

public abstract class SimpleView implements Observer {
 protected JComponent widget_;
 public void update(Observable observable, Object arg) {
  updateView();
 }
 abstract public void updateView();
...
}

Source code

MVC: An example with Observer pattern (6)

final public class SimpleTextFieldView extends SimpleView {    
 private JTextField value_field_ = new JTextField();
 public SimpleTextFieldView(SimpleModel model) {
  ...
  widget_ = new JPanel(new BorderLayout());
  ...
  widget_.add(value_field_, BorderLayout.SOUTH);
 }
 public void updateView() {
  value_field_.setText("" + model_.getValue());
 }
}

Source code

MVC: An example with Observer pattern (7)

public class SimpleSliderView extends SimpleView {
 private JSlider value_slider_ = new JSlider();
 public SimpleSliderView(SimpleModel model) {
  ...
  widget_ = new JPanel(new BorderLayout());
  ...
  widget_.add(value_slider_, BorderLayout.SOUTH);
 }
 public void updateView() {
  value_slider_.setValue(model_.getValue());
 }
}

Source code

MVC: An example with Observer pattern (8)

MVC: An example with Observer pattern (9)

final public class SimpleTextFieldView extends SimpleView {
 public SimpleTextFieldView(SimpleModel model) {
  ...
  value_field_.addActionListener(new TextFieldControllerAction());        
  ...
 }
 class TextFieldControllerAction implements ActionListener {
  public void actionPerformed(ActionEvent event) {
   model_.setValue(Integer.parseInt(value_field_.getText()));
  }
 }
}    

Source code

MVC: An example with Observer pattern (10)

public class SimpleSliderView extends SimpleView {
 public SimpleSliderView(SimpleModel model) {
  ...
  value_slider_.addChangeListener(new SliderControllerAction());        
  ...
 }
 class SliderControllerAction implements ChangeListener {
  public void stateChanged(ChangeEvent event) {
   model_.setValue(value_slider_.getValue());
  }
 }
}

Source code

MVC: An example with Observer pattern (11)

public static void main(String[] args) {
 SimpleModel model = new SimpleModel();
 SimpleView view = new SimpleTextFieldView(model);                
 ...       
 view = new SimpleSliderView(model);        
 ...       
 model.setValue(12);
}

Source code

Complete source code

MVC on the server side (1)

MVC on the server side (2)

Struts - Java-based MVC Web App Framework (1)

Struts - Java-based MVC Web App Framework (1)

img/struts.png

Struts - Java-based MVC Web App Framework (2)

Struts - Java-based MVC Web App Framework (3)

Struts - Java-based MVC Web App Framework (4)

<action-mappings>
...
 <action
   path="/search"
   type="edu.iicm.publication.struts.SearchAction"
   name="search_form"
   scope="request"
   validate="false"
   input="/search.jsp">
  <forward name="html" path="/search_results.jsp"/>
  <forward name="bibtex" path="/search_export.jsp"/>
  <forward name="rdf" path="/search_export.jsp"/>
 </action>
...
</action-mappings>

Struts - Java-based MVC Web App Framework (5)

Struts - Java-based MVC Web App Framework (6)

<form-beans>
...
 <form-bean
  name="search_form"
  type="edu.iicm.publication.struts.SearchForm"/>
...
</form-beans>

Struts - Java-based MVC Web App Framework (7)

Ruby on Rails (1)

Ruby on Rails (2)

Ruby on Rails (3)

Ruby on Rails (4)

Ruby on Rails (5)

Ruby on Rails (6)

class Student < ActiveRecord::Base
end
create table students (
   id            int not null auto_increment,
   name          varchar(80),
   study_field   varchar(10),
   primary key(id)
);

Ruby on Rails (7)

@students = Student.find_all
@student = Student.new

Ruby on Rails (8)

Ruby on Rails (9)

class Student < ActiveRecord::Base
  has_and_belongs_to_many :courses
end

Ruby on Rails (10)

Ruby on Rails (11)

class TestController < ApplicationController
   def index
     render_text "Wow, that was easy"
   end
   
   def hello
     render_text "Hello World"
   end
end

Ruby on Rails (12)

class StudentController < ApplicationController
   scaffold :student
end

Ruby on Rails (13)

Ruby on Rails (14)