12-CRS-0106 REVISED 8 FEB 2013 CSG2H3 Object Oriented Programming.

Slides:



Advertisements
Similar presentations
Spring, Hibernate and Web Services 13 th September 2014.
Advertisements

Chapter 10 THINKING IN OBJECTS 1 Object Oriented programming Instructor: Dr. Essam H. Houssein.
Internet Technologies 1 Master of Information System Management Java Server Faces Model/View/Controller Design Pattern for Web Development Slides.
Java Programming, 3e Concepts and Techniques Chapter 3 Manipulating Data Using Methods.
COMS S1007 Object-Oriented Programming and Design in Java August 7, 2007.
Object-Oriented Analysis and Design
Chapter 7 Improving the User Interface
Application Architectures Vijayan Sugumaran Department of DIS Oakland University.
Structure of a web application1 Dr Jim Briggs. MVC Structure of a web application2.
Chapter Day 9. © 2007 Pearson Addison-Wesley. All rights reserved4-2 Agenda Day 8 Questions from last Class?? Problem set 2 posted  10 programs from.
1 Class 8. 2 Chapter Objectives Use Swing components to build the GUI for a Swing program Implement an ActionListener to handle events Add interface components.
Programming Paradigms Imperative programming Functional programming Logic programming Event-driven programming Object-oriented programming A programming.
Web Application Architecture: multi-tier (2-tier, 3-tier) & mvc
Struts 2.0 an Overview ( )
Io package as Java’s basic I/O system continue’d.
Starting Chapter 4 Starting. 1 Course Outline* Covered in first half until Dr. Li takes over. JAVA and OO: Review what is Object Oriented Programming.
ACM/JETT Workshop - August 4-5, ExceptionHandling and User Interfaces (Event Delegation, Inner classes) using Swing.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
CSCI 6962: Server-side Design and Programming Support Classes and Shopping Carts.
Event Driven Programming
Chapter 8 Script-free pages. Problem with scripting in JSP When you use scripting (declaration, scriplet, expressions) in your JSP, you actually put Java.
12-CRS-0106 REVISED 8 FEB 2013 CSG2H3 Object Oriented Programming.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
12-CRS-0106 REVISED 8 FEB 2013 CSG2H3 Object Oriented Programming.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Software Design 4.1 Tell, Don't Ask l Tell objects what you want them to do, do not ask questions about state, make a decision, then tell them what to.
Java Programming: Guided Learning with Early Objects
Java Event Handling CSIS 3701: Advanced Object Oriented Programming.
12-CRS-0106 REVISED 8 FEB 2013 Java Collection. 12-CRS-0106 REVISED 8 FEB 2013 Java Collection.
Fall CIS 764 Database Systems Engineering L7. EJB’s.
Systems Analysis and Design in a Changing World, 3rd Edition
Refactoring for Testability (or how I learned to stop worrying and love failing tests) Presented by Aaron Evans.
Model View Controller (MVC) Bigger than a Pattern: It’s an Architecture Rick Mercer with help from many others 1.
Chapter 12 Handling Exceptions and Events. Chapter Objectives Learn what an exception is Become aware of the hierarchy of exception classes Learn about.
1 CSC 222: Object-Oriented Programming Spring 2012 netBeans & GUIBuilder  netBeans IDE create/edit/run a project  GUIBuilder JFrame, JButton, JTextField,
An Introduction to Programming and Object Oriented Design using Java 3 rd Edition. Dec 2007 Jaime Niño Frederick Hosch Chapter 18 Integrating user interface.
Concurrent Programming and Threads Threads Blocking a User Interface.
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
ARCH-11: Building your Presentation with Classes John Sadd Fellow and OpenEdge Evangelist Sasha Kraljevic Principal TSE.
Model View Controller (MVC) Bigger than a Pattern: It’s an Architecture Rick Mercer with help from many of others 1.
Advanced Programming Rabie A. Ramadan vpro/ Lecture 4.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
A simple swing example GETTING STARTED WITH WIND CHILL.
(1) Introduction to Java GUIs Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University of Hawaii Honolulu.
1 CSE 331 Model/View Separation and Observer Pattern slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia.
Creating a GUI Class An example of class design using inheritance and interfaces.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 32 JavaBeans and Bean.
Model View Controller (MVC) an architecture Rick Mercer with help from many of others 1.
12-CRS-0106 REVISED 8 FEB 2013 CSG2H3 Object Oriented Programming.
12-CRS-0106 REVISED 8 FEB 2013 CSG2H3 Object Oriented Programming.
Java - hello world example public class HelloWorld { public static void main (String args[]) { System.out.println("Hello World"); }
Lecture10 Exception Handling Jaeki Song. Introduction Categories of errors –Compilation error The rules of language have not been followed –Runtime error.
Object Oriented Programming in Java Habib Rostami Lecture 10.
MIT AITI 2004 Swing Event Model Lecture 17. The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the.
12-CRS-0106 REVISED 8 FEB 2013 CSG2H3 Object Oriented Programming.
ABT1/GUT1/KFT1 Task 4 Prep Diagrams for MediaManager Cynthia Lang, PE, MSChE Pubali Banerjee, PhD IT Course Mentors-Java Assessments.
CS 562 Advanced Java and Internet Application Computer Warehouse Web Application By Team Alpha :-  Puja Mehta (102163)  Mona Nagpure (102147)
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Modular Event Handling
CSC 222: Object-Oriented Programming
Structure of a web application
MPCS – Advanced java Programming
The Object Oriented Approach to Design
PRG 421 MART Higher Education / prg421mart.com
PRG 421 GUIDE Lessons in Excellence -- prg421guide.com.
Event Driven Programming
Constructors, GUI’s(Using Swing) and ActionListner
Java Tutorial – Application Building
Observer pattern, MVC, IO & Files
Presentation transcript:

12-CRS-0106 REVISED 8 FEB 2013 CSG2H3 Object Oriented Programming

12-CRS-0106 REVISED 8 FEB 2013 Architecture vs Pattern ? Define Clear Responsibilities, communication and loose coupling between the three primary components of most user systems VIEW [GUI] CONTROL [Event- Handler] MODEL [Data /Proses]

12-CRS-0106 REVISED 8 FEB 2013 About MVC [1] The model-view-controller (MVC) architecture provides a set of design patterns that help you separate the areas of concern involved in building and running a GUI-based application. The model encapsulates the business logic and persistence code for the application. The model should be as view-technology-agnostic as possible.

12-CRS-0106 REVISED 8 FEB 2013 About MVC [2] The view should display model objects and contain presentation logic only. There should be no business logic or controller logic in the view The controller (along with its attending logic) acts as the mediator between the view and the model. The controller talks to the model and delivers model objects to the view to display.

12-CRS-0106 REVISED 8 FEB 2013 MVC is a software architectural pattern –A paradigm –An approach to structuring the software maintainable and flexible program code Note

12-CRS-0106 REVISED 8 FEB 2013 There’s a lot of approach to achieve it according to what programming language and coding style of the programmer –MVC coding style might differ from one programmer to another –The example here is only one of those Note

12-CRS-0106 REVISED 8 FEB 2013 POJO Class Application Class View Class Controller Class MVC elements

12-CRS-0106 REVISED 8 FEB 2013 Model Class POJO class –Plain Old Java Object According to class diagram Application Class Contains business process functions –as defined in use case diagram Where the other object lives

12-CRS-0106 REVISED 8 FEB 2013 View Class Purely to receive input and display output No business or logic process –Unless it is closely related to the display procedure (presentation logic) Controller Class Connect the view to the application The controller always selects the next view.

12-CRS-0106 REVISED 8 FEB 2013 Model POJO class MVC Approach : Driver Console Driver Console Application class MODEL VIEW CONTROL

12-CRS-0106 REVISED 8 FEB 2013 MVC Approach : 1 view - 1 controller View Controller Model Application class POJO class MODELCONTROL VIEW Controller can be inner class of the view

12-CRS-0106 REVISED 8 FEB 2013 The application object is passed from one view to another MVC Approach : n view - n controller View 1 View 2 View n Controller 1 Controller 2 Controller n Model Application class POJO class MODELCONTROL VIEW

12-CRS-0106 REVISED 8 FEB 2013 MVC Approach : n view - 1 controller View 1 View 2 View n Controller Model Application class POJO class Interface View MODELCONTROL VIEW

12-CRS-0106 REVISED 8 FEB 2013 Tutorial MVC

12-CRS-0106 REVISED 8 FEB 2013 POJO Example : Employee - Manager Employee -idEmployee : String -position : int -birthdate : Date -salary : double / age : int + iterator : static int + Employee( name, birthdate, position ) + setAge() + setSalary() + toString() : String + setter getter Manager -listSubordinate :Employee[] -numSubordinate : int -bonus : int + iterator : static int + Manager( name, birthdate, position, bonus ) + getSalary() + addSubordinate( e : Employee ) + getSubordinate( id ) : Employee + removeSubordinate( id ) + getSubordinateList() : String[] + toString() : String + setter getter

12-CRS-0106 REVISED 8 FEB 2013 Application Class Employee Manager POJO class Application -listEmployee : ArrayList + Application() + insertEmployee( name, birthdate, position ) + insertManager( name, birthdate, position, bonus ) + getEmployee( id ) : Employee + removeEmployee( id ) + promoteEmployee( id, bonus ) + assignmanager( idManager, idEmployee ) + removeAssign( idManager, idEmployee ) + viewEmployee() + getListAllEmployee() : String[] + getEmployeeList() : String[] + getManagerList() : String[]

12-CRS-0106 REVISED 8 FEB 2013 Model Class

12-CRS-0106 REVISED 8 FEB 2013 Employee class

12-CRS-0106 REVISED 8 FEB 2013 Manager class

12-CRS-0106 REVISED 8 FEB 2013 Application Class

12-CRS-0106 REVISED 8 FEB 2013 Application Class

12-CRS-0106 REVISED 8 FEB 2013 Application Class

12-CRS-0106 REVISED 8 FEB 2013 Application Class

12-CRS-0106 REVISED 8 FEB 2013 Application Class

12-CRS-0106 REVISED 8 FEB 2013 Create class to save the object to file or database In this example, we use FileIO class to write/read object into a file –Write/read string to file  public void saveLog(String s, String file) throws IOException  public String readLog(String file) throws FileNotFoundException, IOException –Write/read object to file  public void saveObject(Object o, String filename) throws FileNotFoundException, IOException  public Object getObject(String filename) throws IOException, ClassNotFoundException Application Class : additional

12-CRS-0106 REVISED 8 FEB 2013 Application Class : additional

12-CRS-0106 REVISED 8 FEB 2013 Console-based Application

12-CRS-0106 REVISED 8 FEB 2013 Driver Application class

12-CRS-0106 REVISED 8 FEB 2013 Driver Application class

12-CRS-0106 REVISED 8 FEB 2013 Driver Application class

12-CRS-0106 REVISED 8 FEB 2013 Question?

12-CRS-0106 REVISED 8 FEB 2013 GUI Application

12-CRS-0106 REVISED 8 FEB 2013 View Employee GUI Create a desirable GUI design Give each component a respective variable name

12-CRS-0106 REVISED 8 FEB 2013 View Employee GUI If you’re using an IDE (such as NetBeans), you might want to remove (delete) the main method first

12-CRS-0106 REVISED 8 FEB 2013 View Employee GUI Create a method to perform input-output operation from the components

12-CRS-0106 REVISED 8 FEB 2013 View Employee GUI Create a method to add Event Listener to the action component –Add ActionListener to buttons to listen action when the button pressed –Add MouseAdapter to list to listen action when the list selected

12-CRS-0106 REVISED 8 FEB 2013 View Employee GUI Additional : Create a method to view message such as error message

12-CRS-0106 REVISED 8 FEB 2013 View Employee : Controller Create inner class Controller implements ActionListener –Can be made private Add variable model Application

12-CRS-0106 REVISED 8 FEB 2013 View Employee : Controller create Constructor to call method addListener and addAdapter from the GUI Create method to set the Model Application –Load the data after setting the model

12-CRS-0106 REVISED 8 FEB 2013 View Employee : Controller Define the business process when the button pressed in actionPerformed method

12-CRS-0106 REVISED 8 FEB 2013 View Employee : Controller

12-CRS-0106 REVISED 8 FEB 2013 View Employee : Controller Define the business process to view the detail of selected Employee

12-CRS-0106 REVISED 8 FEB 2013 View Employee : Controller Add/change a constructor so when the view will instantiate the controller on call Run the app by calling the View on driver class

12-CRS-0106 REVISED 8 FEB 2013 Instantiate the new view Pass the model application object to the new view Close the current view Example : Move from one view display to another

12-CRS-0106 REVISED 8 FEB 2013 Question?

12-CRS-0106 REVISED 8 FEB 2013 THANK YOU Credits M usic : Yonezawa Madoka - Oui! Ai Kotoba (Instrumental)