CSC 211 Introduction to Design Patterns. Intro to the course Syllabus About the textbook – Read the introduction and Chapter 1 Good attendance is the.

Slides:



Advertisements
Similar presentations
Chapter 1 Inheritance University Of Ha’il.
Advertisements

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.
Inheritance Inheritance Reserved word protected Reserved word super
Advanced Programming in Java
Sadegh Aliakbary Sharif University of Technology Fall 2010.
ITEC200 – Week03 Inheritance and Class Hierarchies.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 1 Object-Oriented.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 1 Abstract Classes and Interfaces.
Liang,Introduction to Java Programming,revised by Dai-kaiyu 1 Chapter 10 Object-Oriented Modeling.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
1 Object-Oriented Design. 2 Objectives F To become familiar with the process of program development. F To the relationship types: association, aggregation,
Chapter 10 Classes Continued
8.1 Classes & Inheritance Inheritance Objects are created to model ‘things’ Sometimes, ‘things’ may be different, but still have many attributes.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
CC1007NI: Further Programming Week Dhruba Sen Module Leader (Islington College)
CSCI-383 Object-Oriented Programming & Design Lecture 15.
Subclasses and Subtypes CMPS Subclasses and Subtypes A class is a subclass if it has been built using inheritance. ▫ It says nothing about the meaning.
Inheritance. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 Inheritance Inheritance is a fundamental object-oriented design technique used to.
Introduction To System Analysis and design
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented Design.
Design Patterns.
Introduction to Object-oriented programming and software development Lecture 1.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
An Object-Oriented Approach to Programming Logic and Design
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Objectives Lecture 11 : Frameworks SWE 316: Software Design and Architecture  To understand.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
1 Java Inheritance. 2 Inheritance On the surface, inheritance is a code re-use issue. –we can extend code that is already written in a manageable manner.
Polymorphism, Inheritance Pt. 1 COMP 401, Fall 2014 Lecture 7 9/9/2014.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Specialization and Inheritance Chapter 8. 8 Specialization Specialized classes inherit the properties and methods of the parent or base class. A dog is.
CSE 331 SOFTWARE DESIGN & IMPLEMENTATION MIDTERM REVIEW Autumn 2011.
Course Overview & Topics CSc 335: Object-Oriented Programming and Design © Rick Mercer 1.
Chapter 2 Introducing Interfaces Summary prepared by Kirk Scott.
1-1 C Sc 335 Course Overview Object-Oriented Programming and Design Rick Mercer.
Object Oriented Software Development
CS2110: SW Development Methods Inheritance in OO and in Java Part 2: Topics: Forms of inheritance Interfaces in Java.
Inheritance. Inheritance is a fundamental object-oriented design technique used to create and organize reusable classes Chapter 8 focuses on: deriving.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
(1) ICS 313: Programming Language Theory Chapter 12: Object Oriented Programming.
1 Chapter 5:Design Patterns. 2 What are design pattern?  Schematic description of design solution to recurring problems in software design and,  Reusable.
Interfaces Chapter 9. 9 Creating Interfaces An interface is a contract. Every class that implements the interface must provide the interface’s defined.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 11 Object-Oriented.
Java Software Solutions Lewis and Loftus Chapter 9 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Enhanced Class Design -- Introduction.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Banaras Hindu University. A Course on Software Reuse by Design Patterns and Frameworks.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
Chapter 2 Principles of Programming and Software Engineering.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Design Patterns: MORE Examples
Object-Oriented Design
Chapter 5:Design Patterns
Introduction to Design Patterns
Chapter 11 Object-Oriented Design
Plan for today Refactoring and Design Patterns
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
PRINCIPALES OF OBJECT ORIENTED PROGRAMMING
Chapter 10 Thinking in Objects
Chapter 10 Thinking in Objects
Interface.
Interfaces.
Advanced Java Programming
Chapter 14 Abstract Classes and Interfaces
Review of Previous Lesson
CS 112 Programming 2 Lecture 02 Abstract Classes & Interfaces (2)
Presentation transcript:

CSC 211 Introduction to Design Patterns

Intro to the course Syllabus About the textbook – Read the introduction and Chapter 1 Good attendance is the key to an easy ride

Background CS1 - Programming and Control Structures CS2 - Data Structures - common patterns for storing and retrieving data CSC211 - Design Patterns - common architectural patterns – Broader, more sophisticated view

A little about design patterns This course is an introduction to software design patterns. Each pattern represents a best practice solution to a software problem in some context. Design patterns are just convenient ways of reusing object oriented code between projects and programmers. Write down and catalog common interactions between objects that programmers have frequently found useful.

What’s a design pattern? Model, view, controller (MVC) pattern in Java Swing In other words, design patterns describe how objects communicate without become entangled in each other’s data models and methods. Keeping this separation has always been an objective of good OO programming

OOP – Review of Basics Abstraction Class Object Instance

Inheritance When one class is defined to include methods and fields from another class Subclass vs. Superclass – Child vs. parent How do we code that in Java?

Substitution Principle Let q(x) be a property provable about objects x of type T. Then q(y) should be true for objects y of type S where S is a subtype of T In other words, if S is a subtype of T, then objects of type T in a program may be replaced with objects of type S without altering any of the desirable properties of that program

Substitution Principle’s Effects Preconditions cannot be strengthened in a subclass. Remember method preconditions? Postconditions cannot be weakened in a subclass. No new exceptions should be thrown by subclass methods – except where exceptions are subtypes of superclass exceptions

Abstract Class A class that cannot be instantiated Why would we do that?

Interface Defines a set of method signatures A class that implements the interface promises it will implement signature methods Response to Java not allowing inheritance from multiple superclasses Essentially allows a subclass to be substituted for multiple superclasses. – However only one of those superclasses can contain more than method signatures.

Interface and abstract class Java has a class like form called an interface that can be used to encapsulate only abstract methods and constants. Think of an interface as a blueprint or a design specification. A class that uses this blueprint is a class that implements the interface. Another way of thinking of an interface is as a pure abstract class, wherein all the details are deferred. An interface is allowed to have only abstract methods and constants. Interface methods can’t be static. An interface is allowed to have only public methods, and by convention the keyword public is omitted. Because all methods in an interface are abstract, the keyword abstract is also omitted. A new class implementing the interface uses the keyword implements. The class that implements the interface must provide an implementation for all methods in the interface. The difference between an interface and an abstract class becomes very important when you want to create a class that implements more than one interface. You can’t extend more than one class, but you can use a class to implement many interfaces, in addition to extending one class.

Type Polymorphism Declaring an instance of a subclass to be of a type of its superclass or an interface its class implements Ex. Purrer kitty = new HouseCat();

Is-A versus Has-A A sub-class has an “Is-A” relationship with its superclass A class has an “Is-A” relationship with any interface it implements A class has a “Has-A” relationship with any class that is the type of one of its instance variables

What are design patterns? Common ways that classes are structured to solve similar types of problems Frameworks for classes, objects, and interfaces that can be applied to a wide variety of situations Thinking about the design of the system at a higher level A solution to a problem in a context -- (textbook def.)

Design Patterns Give us Vocabulary Shared vocabulary that we use to discuss design alternatives Data structures began that vocabulary at a lower level That vocabulary lets us describe alternatives efficiently

What design patterns aren’t They aren’t data structures – Data structures can be implemented once and shared between many applications – Even if two applications use the same patterns, each will have to implement the details for their own problems. They aren’t libraries or APIs

Design Patterns and Thought Design Patterns are ways of thinking about potential solutions to complex problems They obey good OO design principles and have been shown to be widely applicable We need to be able to think at a higher level

Our interest What makes a design “good”? What design principles support good designs? Proven design techniques

Strategy for Building Big Systems How do we know what to build? How will we know that it works? How will we deal with changes that come up as we learn more about the requirements and the system?

Test Driven Development Write automated tests before writing the code Iterative Development: – Red - write a test and watch it fail – Green - write the simplest code that can make the test pass – Refactor - clean up the code to eliminate duplication

Why do we write the test first? Help us plan the code we’re going to write Help us focus on how people will use our code (not just what it has to do)

How do the tests help? We know the system works We can refactor with confidence Serve as design documentation – Javadocs document structure – Tests document behavior – These work well together

Homework For lab (We’ll do a lab to practice TDD) – Read about JUnit testing framework at For next week – Read book from beginning through the Strategy Pattern In general – Quizzes on Tuesday – Cover a pattern Starting on Tuesday with a lab later in the week – Read about the pattern BEFORE you come to class on Tuesday (it’s on the quiz!)