Cs 415 n tier application development
This presentation is the property of its rightful owner.
Sponsored Links
1 / 43

CS 415 N-Tier Application Development PowerPoint PPT Presentation


  • 75 Views
  • Uploaded on
  • Presentation posted in: General

National University of Computer and Emerging Sciences. Lecture # 4 Web Presentation Patterns ( MVC, Page Controller, Front Controller ). CS 415 N-Tier Application Development. By Umair Ashraf June 25 ,2013. Contents. MVC (Model, View Controller) Pattern Web Presentation Patterns:

Download Presentation

CS 415 N-Tier Application Development

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Cs 415 n tier application development

National University of Computer and Emerging Sciences

Lecture # 4

Web Presentation Patterns (MVC, Page Controller, Front Controller)

CS 415 N-Tier Application Development

By Umair Ashraf

June 25 ,2013


Contents

Contents

  • MVC (Model, View Controller) Pattern

    Web Presentation Patterns:

  • MVC (Model, View Controller) Pattern

  • Page Controller Pattern

  • Front Page Controller Pattern

    Practical Demonstration


Cs 415 n tier application development

public interface BeatModelInterface {

void initialize();

void on();

void off();

void setBPM(intbpm);

intgetBPM();

void registerObserver(BeatObserver o);

void removeObserver(BeatObserver o);

void registerObserver(BPMObserver o);

void removeObserver(BPMObserver o);

}


Cs 415 n tier application development

  • public class BeatModel implements BeatModelInterface, MetaEventListener {

  • Sequencer sequencer;

  • ArrayListbeatObservers = new ArrayList();

  • ArrayListbpmObservers = new ArrayList();

  • intbpm = 90;

  • //other instance variables here

  • public void initialize() {

  • setUpMidi();

    • buildTrackAndStart();

  • }

  • public void on() {

  • sequencer.start();

  • setBPM(90);

  • }

  • public void off() {

  • setBPM(0);

  • sequencer.stop();

  • }


Cs 415 n tier application development

public void setBPM(intbpm) {

this.bpm = bpm;

sequencer.setTempoInBPM(getBPM());

notifyBPMObservers();

}

public intgetBPM() {

return bpm;

}

void beatEvent() {

notifyBeatObservers();

}

//code to register and notify observers

//Lots of MIDI code to handle the beat

}


Cs 415 n tier application development

public class DJView implements ActionListener, BeatObserver, BPMObserver {

BeatModelInterface model;

ControllerInterface controller;

JFrameviewFrame;

JPanelviewPanel;

BeatBarbeatBar;

JLabelbpmOutputLabel;

public DJView(ControllerInterface controller, BeatModelInterface model) {

this.controller = controller;

this.model = model;

model.registerObserver((BeatObserver)this);

model.registerObserver((BPMObserver)this);

}

public void createView() {

//Create all Swing components here

}


Cs 415 n tier application development

public void updateBPM() {

intbpm = model.getBPM();

if (bpm == 0) {

bpmOutputLabel.setText("offline");

} else {

bpmOutputLabel.setText("Current BPM: " + model.getBPM());

}

}

public void updateBeat() {

beatBar.setValue(100);

}

}


Cs 415 n tier application development

public class DJView implements ActionListener, BeatObserver, BPMObserver {

BeatModelInterface model;

ControllerInterface controller;

JLabelbpmLabel;

JTextFieldbpmTextField;

JButtonsetBPMButton;

JButtonincreaseBPMButton;

JButtondecreaseBPMButton;

JMenuBarmenuBar;

JMenu menu;

JMenuItemstartMenuItem;

JMenuItemstopMenuItem;

public void createControls() {

//Create all Swing components here

}


Cs 415 n tier application development

public void enableStopMenuItem() {

stopMenuItem.setEnabled(true);

}

public void disableStopMenuItem() {

stopMenuItem.setEnabled(false);

}

public void enableStartMenuItem() {

startMenuItem.setEnabled(true);

}

public void disableStartMenuItem() {

startMenuItem.setEnabled(false);

}

public void actionPerformed(ActionEvent event) {

if (event.getSource() == setBPMButton) {

intbpm = Integer.parseInt(bpmTextField.getText());

controller.setBPM(bpm);

} else if (event.getSource() == increaseBPMButton) {

controller.increaseBPM();

} else if (event.getSource() == decreaseBPMButton) {

controller.decreaseBPM();

}

}

}


Cs 415 n tier application development

public interface ControllerInterface {

void start();

void stop();

void increaseBPM();

void decreaseBPM();

void setBPM(intbpm);

}


Cs 415 n tier application development

public class BeatController implements ControllerInterface {

BeatModelInterface model;

DJView view;

public BeatController(BeatModelInterface model) {

this.model = model;

view = new DJView(this, model);

view.createView();

view.createControls();

view.disableStopMenuItem();

view.enableStartMenuItem();

model.initialize();

}

public void start() {

model.on();

view.disableStartMenuItem();

view.enableStopMenuItem();

}


Cs 415 n tier application development

public void stop() {

model.off();

view.disableStopMenuItem();

view.enableStartMenuItem();

}

public void increaseBPM() {

intbpm = model.getBPM();

model.setBPM(bpm + 1);

}

public void decreaseBPM() {

intbpm = model.getBPM();

model.setBPM(bpm - 1);

}

public void setBPM(intbpm) {

model.setBPM(bpm);

}

}


Cs 415 n tier application development

public class DJTestDrive {

public static void main (String[] args) {

BeatModelInterface model = new BeatModel();

ControllerInterface controller = new BeatController(model);

}

}


Ludo game in mvc

LUDO Game in MVC


Mvc implementation in asp net

MVC implementation in ASP.NET

Practical Demonstration


Page controller pattern

Page Controller Pattern

Use the Page Controller pattern to accept input from the page request, invoke the requested actions on the model, and determine the correct view to use for the resulting page


Page controller pattern1

Page Controller Pattern


Page controller in asp net

Page Controller in ASP.NET


Front page controller pattern

Front Page Controller Pattern

Front Controller solves the decentralization problem present in Page Controller by channeling all requests through a single controller. The controller itself is usually implemented in two parts: a handler and a hierarchy of commands 


Reference material

Reference Material

Text Book :Head First Design Patterns by GOF

(EBook uploaded on website )

Web Presentation Patterns :

http://msdn.microsoft.com/en-us/library/ff650511.aspx


  • Login