Programming for Geographical Information Analysis: Core Skills Lecture 11: Coding for Real Dr Andy Evans and Dr Kirk Harland.

Slides:



Advertisements
Similar presentations
Testing Relational Database
Advertisements

Introduction to Java 2 Programming Lecture 10 API Review; Where Next.
Welcome to. Who am I? A better way to code Design Patterns ???  What are design patterns?  How many are there?  How do I use them?  When do I use.
Programming Paradigms and languages
IMS1805 Systems Analysis Topic 3: Doing Analysis (continued from previous weeks)
Framework is l Reusable Code, often domain specific (GUI, Net, Web, etc) l expressed as l a set of classes and l the way objects in those classes collaborate.
DESIGN PATTERNS OZGUR RAHMI DONMEZ.
Copyright 2004 Monash University IMS5401 Web-based Systems Development Topic 2: Elements of the Web (g) Interactivity.
CS 290C: Formal Models for Web Software Lecture 10: Language Based Modeling and Analysis of Navigation Errors Instructor: Tevfik Bultan.
Design Patterns CS is not simply about programming
CSI 101 Elements of Computing Spring 2009 Lecture #2 Development Life Cycle of a Computer Application Monday January 26th, 2009.
Package design and the Iterative process model. What is a package? Classes are not sufficient to group code –Some classes collaborate, implying dependencies.
Part or all of this lesson was adapted from the University of Washington’s “Web Design & Development I” Course materials.
Proxy Design Pattern Source: Design Patterns – Elements of Reusable Object- Oriented Software; Gamma, et. al.
Struts 2.0 an Overview ( )
Copyright © 2002, Systems and Computer Engineering, Carleton University Intro.ppt * Object-Oriented Software Development Unit 1 Course.
Chapter 2: Approaches to System Development
Design Patterns Standardized Recurring model Fits in many location Opposite of customization Fundamental types of pattern Choose and use as desired and.
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Objectives Lecture 11 : Frameworks SWE 316: Software Design and Architecture  To understand.
Design patterns. What is a design pattern? Christopher Alexander: «The pattern describes a problem which again and again occurs in the work, as well as.
CS 360 Lecture 3.  The software process is a structured set of activities required to develop a software system.  Fundamental Assumption:  Good software.
1 SYS366 Lecture 1: Introduction to Systems. 2 What is Software Development? Software Development implies developing some software – but it does not involve.
05 - Patterns Intro.CSC4071 Design Patterns Designing good and reusable OO software is hard. –Mix of specific + general –Impossible to get it right the.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
1 SAD2 - UML 4 th Lecture Class Diagram in Construction Phase Patterns Case Study Lecturer: Dr Dimitrios Makris
January 12, Introduction to Design Patterns Tim Burke References: –Gamma, Erich, et. al. (AKA, The Gang of Four). Design Patterns: Elements of Reusable.
Design Patterns in Java Chapter 1 Introduction Summary prepared by Kirk Scott 1.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
The Systems Development Life Cycle
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
18 April 2005CSci 210 Spring Design Patterns 1 CSci 210.
Software Design Patterns (1) Introduction. patterns do … & do not … Patterns do... provide common vocabulary provide “shorthand” for effectively communicating.
Object Oriented Software Engineering Chapter 16 and 17 review 2014/06/03.
Testing Extensible Design Patterns in OO Frameworks through Scenario Templates D.S. Sanders Software Verification & Validation.
ECE450S – Software Engineering II
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
Introduction to Design Patterns. Questions What is a design pattern? Who needs design patterns? How different are classes and objects in APL compared.
The Software Development Process
Behavioral Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Sadegh Aliakbary. Copyright ©2014 JAVACUP.IRJAVACUP.IR All rights reserved. Redistribution of JAVACUP contents is not prohibited if JAVACUP.
Connecting with Computer Science2 Objectives Learn how software engineering is used to create applications Learn some of the different software engineering.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Design Patterns Introduction
CS251 – Software Engineering Lectures 18: Intro to DP Slides by Rick Mercer, Christian Ratliff, Oscar Nierstrasz and others 1 و ابتغ فيما آتاك الله الدار.
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
Java – in context Main Features From Sun Microsystems ‘White Paper’
Design Patterns in Context ©SoftMoore ConsultingSlide 1.
Java Programming: Advanced Topics1 Introduction to Advanced Java Programming Chapter 1.
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
1 SYS366 Week 1 - Lecture 1 Introduction to Systems.
Software Development Process CS 360 Lecture 3. Software Process The software process is a structured set of activities required to develop a software.
Slides prepared by Rose Williams, Binghamton University Chapter 20 Java Never Ends.
OCR A Level F453: The function and purpose of translators Translators a. describe the need for, and use of, translators to convert source code.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns CSCE 315 – Programming Studio Spring 2013.
GRASP – Designing Objects with Responsibilities
Chapter 10 Design Patterns.
Chapter 5:Design Patterns
Introduction to Advanced Java Programming
MPCS – Advanced java Programming
Introduction to Design Patterns
Structure We saw early on the importance of algorithms, but what about structuring our code? What's the best way to structure a larger project made of.
Development Processes
Design and Maintenance of Web Applications in J2EE
Development Processes
Advanced Programming Behnam Hatami Fall 2017.
Informatics 122 Software Design II
(Computer fundamental Lab)
Informatics 122 Software Design II
Structure We saw early on the importance of algorithms, but what about structuring our code? What's the best way to structure a larger project made of.
Presentation transcript:

Programming for Geographical Information Analysis: Core Skills Lecture 11: Coding for Real Dr Andy Evans and Dr Kirk Harland

This lecture The development process Structuring code Testing

Development Processes Considerable debate around how best to manage software development. Most proposed ‘processes’ have a parentage in the ‘Waterfall Model’; roughly: Requirements Design Coding Testing Installation Maintance Like a good many parents who try their best, its children have nothing good to say about it.

Critiques Largely focused on the fact that software was never fully completed, but always being re-visited at different scales. In particular, it is unhelpful not to go back to users and consult once a basic system is drafted. Popular alterative is Iterative and Incremental development, where, after initial Requirements are outlined, there is a cycling through the development units, taking important and high-risk elements first. This is sometimes combined with the Waterfall model as the ‘Iterfall model’. Experience suggests the broad sweep of this matches with beginner’s natural inclinations.

New processes Based on the Iterative and avoiding the over-management of the Waterfall method: Agile software development processes include: Rational Unified Process Extreme Programming Kanban and SCRUM for communication Short development sprints Continuous Integration Main issue is to concentrate on user needs.

UML An intrinsic part of the development process. From: Use Cases Through: Class Diagrams To: Activity Diagrams

Development stages Refining user requirements. Dividing code (e.g. by important high-risk functions first). Keeping users informed. Development. Usability testing. Bug hunting. Refactoring. Alpha and Beta testing. Releases. Deciding on the next set of functions to tackle. Increasingly releases tackle a few functions on a short timescale rather than major releases with a longer gap (“RERO”).

Licensing Different options on a spectrum: Open source. Maintenance contracts. Open standards. Community built. Freeware. Adware. Commercial.

Computer Ethics Rapidly growing field: Traditional elements: Privacy and data protection Copyright and Piracy Software supplier responsibilities Newer: Big Data use Robotic ethics Control by computers Integrating computers into our worldview A good starting point for the newer stuff is Floridi et al.:

Installing Three parts to installation… Get the files to them. Check they have the JDK. Let them run the program. Ideally we want to let them run by double-clicking a name or icon… Can get them to set this up as a shortcut themselves. Can compile as a.exe. Can use a self-executing jar file. Can use a.bat file or wrapping exe.

Summary Getting a strong project outline at the start will help you resource a project, as will having a clear delimitation of coding activities. However, project frameworks need to have flexibility built in to cope with project evolution. Start with an ordered list of functionalities, but consult with users frequently. Look into formal software development processes if you have to work with teams.

This lecture The development process Structuring code Testing

Structure we’ve seen Blocks Exception handling Methods Classes Packages How do we judge where code should go?

Coupling and Cohesion Good OO design calls for LOOSE coupling and HIGH cohesion. Coupling is the degree to which two classes 'know about each other'. Just uses public interface methods: low coupling. Uses internal code, e.g. internal variables: high coupling. Cohesion is the purpose of the class. Is it well focused?

Coupling Close coupling causes issues for code maintenance. Enhancement or bug fixes to a class should be possible without impacting the interface it presents. Assumption is that changes will not impact anywhere else, why should it if the interface has not changed. A close coupled class means if part of the code changed, the alteration has an undetected impact. Close coupling limits code reuse because you can’t just separate off one class.

Cohesion A class with high cohesion has a well defined purpose. Classes designed with high cohesion are: Easier to maintain. Less likely to require frequent changes. Easier to reuse in multiple projects / applications. Tend to be simpler to follow for other developers. Generally have a well defined interface.

High Cohesion Loose Coupling Remember when designing a class: Define the purpose and don't let that creep. Keep the inner functions of the class private. Think about how you want other classes to interact with this class and define its interface accordingly. Ask yourself, how easy would this class be to reuse in another project?

Structure we’ve seen Blocks Exception handling Methods Classes Packages Others we haven’t: threads, parallelisation, other programs

Getting processor time Usually a program will take over the processor once and run through the code a line at a time in one go. However, you can force the processor to split up and run several copies of the same bit of code. Each runs in its own processor “thread” of execution. For example, you might want a web server to have one thread for each person accessing files so you can send the right file back to the right person, even though lots of requests are being made simultaneously.

Threads Implement java.lang.Runnable interface and make a Thread object inside the class. Extend java.lang.Thread class – this implements Runnable. Either way you need a Runnable object and a Thread object You need to call the Thread’s start() method. This will look in the Runnable object for a run() method.

synchronized The synchronized keyword stops more than one Thread / method at a time using the code. Can be applied to methods and blocks. The latter means you can synchronize object methods, even if you didn’t write the class. synchronized(theirObject) { theirObject.theirMethod(); }

Parallel Supercomputing Split up a program so it runs on multiple computers. For example, each computer does the calculation for a different geographical area.

Starting other programs The environment the program is running in is encapsulated by a java.lang.Runtime object. The current Runtime can be got with a static method. Runtime rt = Runtime.getRuntime(); Runtime has methods to: Deal with the computer memory. Interact with the JVM interpreter. Run other programs.

Starting other programs Other programs can be run by the JVM. They are encapsulated in a java.lang.Process object. These can be got using the current Runtime. Process processObject = runtimeObject.exec(“programlocation”); If the OS knows where a program is (i.e. it’s in the PATH), we can just use a name. Also a version of exec that takes in this and an array of arguments, as if the program was running at the command line.

Interacting with other Programs Once started you can use Process methods to drive the programs. Reading from Processes… processObject.getInputStream() Writing to Processes… processObject.getOutputStream() Stopping Processes… processObject.destroy()

Structure we’ve seen Blocks Exception handling Methods Classes Packages Threads / Parallelisation Other programs Where do we get advice?

Patterns “Patterns” are standard ways of solving a software problem that people come across again and again. They aren’t specific to Java, or any other language. They save us having to reinvent solutions. The most influential book in the field was Design Patterns – Elements of Reusable Software by the “Gang of Four” Gamma, Helm, Johnson and Vlissides (1995).

The Gang of Four Patterns They gave 23 patterns with C examples. Creational Patterns – classes to make stuff. The Factory, Abstract Factory, Singleton, Builder, and Prototype. Structural Patterns – software architecture. The Adapter, Bridge,Composite, Decorator, Fa ç ade, Flyweight and Proxy. Behavioural Patterns – which classes do what. The Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template, and Visitor.

Patterns we’ve seen Observer : Listeners. Model-View-Controller: Swing. Adapter Pattern: AWT. Iterator

Why Use Patterns? Industry standard methods of doing something, therefore other programmers will understand your code. They encapsulate solutions so you can get on with more tricky things. They’ll give you a deeper understanding of why Java is the way it is. They’re the advice of top experts with years of experience – they’ll teach you a lot about good Object Orientated software design.

Book

Summary Good Object Orientated code structure encourages robust and reusable software. Read up on patterns: they’ll teach you about good program style, and help solve major issues.

This lecture The development process Structuring code Testing

Timing a program Get the current time in various places and print it out. long time = System.currentTimeMillis() Where milliseconds is since January 1, 1970, 00:00:00 GMT. If you want to see this as a proper date, use a java.util.Date object new Date(long milliseconds) Methods to find if a date is before or after a Date, or set the date in it.

Checking memory Computers store most of the information they need to do processing in a memory chip. If the space available is exceeded by the data, most write to Virtual Memory – this is part of the harddrive and acts as if it’s “real” memory. Using Virtual Memory is slow, because it uses magnetic media that are slow to write to. If the Virtual Memory is exceeded, processing will become very slow, and the system unstable. Java therefore has built in memory limits.

Finding out about the computer Remember, the environment the program is running in is encapsulated by a java.lang.Runtime object. The current Runtime can be got with a static method. Runtime rt = Runtime.getRuntime(); Runtime has methods to Deal with the computer memory. Interact with the JVM interpreter.

Computer memory Java copes with memory well, but occasionally we may want to check it. For example, if a file is much larger than the real memory, we may want to only read in small chunks at a time. runtimeObject.freeMemory() runtimeObject.totalMemory() These return the free and total memory available in the computer.

Garbage Collection Garbage Collection is a general computing term for clearing up objects we no longer need from memory. Objects will stay in memory until collected, even if not used. Java does automatic Garbage Collection, when memory gets low, but you may want to force it. runtimeObject.gc();

Unit Testing A way to ensure that methods have the desired ‘behaviour’ Decide on behaviour Write tests Write code to satisfy tests Time consuming Produces robust code Future maintenance is easier

Other tests Stress testing Alpha/Beta releases Usability Regression testing Software testing

Summary Good code structure centres on building to interfaces: are the inputs and outputs to methods and classes reliable, and do they respond well if things go wrong. Get this right, and you’ll minimise bugs. Unit testing formalises this. However, also test usability and go through alpha and beta test releases.

This lecture The development process Structuring code Testing The End

Core language elements Java 1.5 additions Other core elements Language forms

Variable method arguments “…” to send in an undefined number of method params. Enumerations Set up sequences, eg. WHITE, YELLOW, RED, BLUE, BLACK Autoboxing Wrappers to primitives. E.g. vector.add(myInt++); Static imports Just import the static parts of classes. markup, but can be accessed programmatically. Java 1.5 additions

Other core elements Cloning Automatically copying entire objects. ImageFilters Using streams to convert pixels on the fly.

Language forms JavaBeans Have drag-and-drop interface. Set and Get methods key to getting these working. Servlets Programs that can be started and run by a web server by requesting them as a webpage. Java Server Pages (JSP) Webpages that contain small programs – when the pages are sent out, the output from the programs generates HTML.

Other languages C++ VB.Net Javascript Python

Advanced course: “advanced” as in “progress”, not “difficulty”. Programming ArcGIS Database connectivity Using analysis libraries Visualising data Supercomputing Building an artificial intelligence for predictive modelling.

Further information The GEOG5990 website for subjects we’ve covered: All the lectures. All the handouts. Examples, practice pieces, and useful links. The book recommendations. UML, Cookbook, and Patterns books are a definite “must have” if you go on to code professionally – they’ll teach you good coding practise as well as industry standards. The Java website.

Main thing Practice

Assessment 2 Sign up Practical Tank battle