Software Design Lecture : 12.

Slides:



Advertisements
Similar presentations
Object Oriented Programming
Advertisements

Final and Abstract Classes
Understand and appreciate Object Oriented Programming (OOP) Objects are self-contained modules or subroutines that contain data as well as the functions.
Abstract Class, Packages and interface from Chapter 9
Polymorphism Method overriding Method overloading Dynamic binding 1.
Reusable Classes.  Motivation: Write less code!
Object Oriented Programming in Java. Object Oriented Programming Concepts in Java Object oriented Programming is a paradigm or organizing principle for.
Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
Inheritance Inheritance Reserved word protected Reserved word super
Inheritance and object compatibility Object type compatibility An instance of a subclass can be used instead of an instance of the superclass, but not.
More about classes and objects Classes in Visual Basic.NET.
 In inheritance the child (subclass) chooses its parent (superclass)  Remember - only public or “protected” methods and variables are inherited  Should.
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Chapter 7 - Generalization/Specialization and Inheritance1 Chapter 7 Generalization/Specialization and Inheritance.
Abstraction, Inheritance, and Polymorphism in Java.
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
An Object-Oriented Approach to Programming Logic and Design
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
Topic 4 Inheritance.
CSE 341, S. Tanimoto Java brief review - 1 Java Brief Review Java’s strengths Object-oriented terminology Inheritance Interfaces An example with inheritance.
Object Oriented Programming
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
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.
AD Lecture #1 Object Oriented Programming Three Main Principles 1 Inheritance Encapsulation Polymorphism.
FEN 2014UCN Teknologi/act2learn1 Object-Oriented Programming “ The Three Pillars of OOP”: Encapsulation Inheritance Polymorphism The Substitution Principle.
1 / 71 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 4 Programming Fundamentals using Java 1.
Inheritance ndex.html ndex.htmland “Java.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
OOPS CONCEPT.  OOPS  Benefits of OOPs  OOPs Principles  Class  Object Objectives.
Polymorphism Lecture - 9.
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Abstract Classes, Abstract Methods, Override Methods
Modern Programming Tools And Techniques-I
Object-Oriented Design
Object-Oriented Programming Concepts
Inheritance ITI1121 Nour El Kadri.
Lecture 12 Inheritance.
Objects First with Java A Practical Introduction using BlueJ
University of Central Florida COP 3330 Object Oriented Programming
Final and Abstract Classes
Inheritance and Polymorphism
OOP What is problem? Solution? OOP
Polymorphism.
Week 4 Object-Oriented Programming (1): Inheritance
Chapter 11 – Interfaces and Polymorphism
Inheritance Often, software encapsulates multiple concepts for which some attributes/behaviors overlap E.g. A computer (role-playing) game has: Monsters:
Inheritance B.Ramamurthy 11/7/2018 B.Ramamurthy.
Object Oriented Analysis and Design
Lecture 23 Polymorphism Richard Gesick.
OBJECT ORIENTED PROGRAMMING II LECTURE 8 GEORGE KOUTSOGIANNAKIS
MSIS 670 Object-Oriented Software Engineering
Week 6 Object-Oriented Programming (2): Polymorphism
Subtype Polymorphism, Subtyping vs
Software Design Lecture : 11.
Software Design Lecture : 14.
Polymorphism Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition, by Kernighan.
Object Oriented Programming
Polymorphism and Type Casting
Objects First with Java A Practical Introduction using BlueJ
Objects First with Java A Practical Introduction using BlueJ
Final and Abstract Classes
Programming in C# CHAPTER 5 & 6
Presentation transcript:

Software Design Lecture : 12

Software Design Components Principle Criteria Techniques (this lecture)

Open / Close Principle Bertrand Meyer: “Software entities like classes, modules and functions should be closed but open for extension. Closed The source code of the module inviolate; no one is allowed to make changes to the code the module can be used without risk

Open / Close Principle Open The module is open for extension according to new requirements the module can be extended to behave in new and different ways.

Open / Closed Principle A module that is open for extension is a module whose behavior can be altered to suit new requirements. A module that is closed for modification is a module whose source code is frozen and cannot be changed

The “Open/Closed principle” – Usage in an object oriented paradigm The Open/Closed principle can be applied in object oriented paradigms with the help of inheritance and polymorphism: The interface of the module becomes an abstract class A If needed new Subclasses of A can be derived; these subclasses may extend A

What is Class Basic implementation unit in OOP. It encapsulate data members and methods. Classes have objects or classes are assessed via their objects. Data members are accessed through getters and setters methods.

public class test { int a ; float b; public class() {} void seta(int a) this.a=a; } int geta () return this.a;

Abstract Classes Abstract class is a class that can not be instantiated, it exists extensively for inheritance and it must be inherited. There are scenarios in which it is useful to define classes that is not intended to instantiate; because such classes normally are used as base-classes in inheritance hierarchies

Inheritance It implies the functionality of data sharing between super and sub class. All the data members and methods of super class are available for use in sub class but not vice-versa. Subclass extends the functionality of super class to use the base class methods.

Example of Abstract class and Inheritance In an object-oriented drawing application, you can draw circles, rectangles, lines, Bezier curves, and many other graphic objects. These objects all have certain states (for example: position, orientation, line color, fill color) and behaviors (for example: moveTo, rotate, resize, draw) in common.

abstract class GraphicObject { int x, y; void moveTo(int newX, int newY) { ... } abstract void draw(); abstract void resize(); }

class Circle extends GraphicObject { void draw() { ... } void resize() }

Polymorphism In the context of object-oriented programming, is the ability to create a variable, a function, or an object that has more than one form. Polymorphism is the ability to process objects differently depending on their data types. Polymorphism is the ability to redefine methods for derived classes.

Types of Polymorphism Compile time Polymorphism Compile time Polymorphism also known as method overloading Method overloading means having two or more methods with the same name but with different signatures

Example of Compile Time Polymorphism

Runtime Polymorphism Run time Polymorphism also known as method overriding Method overriding means having two or more methods with the same name , same signature but with different implementation

Example of Run-time Polymorphism

Example We have to design a banking system in which there are several clients who are availing the facility of maintaining the account in the bank. As an international norm bank is offering multiple type of accounts to it’s customers like savings, current etc. Each account is having a facility of deposit and withdrawal attached with it for it’s client.

Example Task to do: We have to design the system in such a way that should accommodate the addition of new account types i-e profit and loss account etc without change in the design of the system

Another Example You are going to design a library application where a particular request for issuance of book is passed through a issueValidator to approve the issue request. The issuanceValidator looks to see if the balance of book is above certain values and then approves the request. Given this problem, one of the developer comes up with the following classes. The libraryrequestHandler can assess a issue request. This class holds the balance of remaining books and period of hold of books for a particular student account.

Code in Java

public class libraryRequestHandler { private int balance; private int period; public libraryRequestHandler(int balance, int period) { this.balance = balance; this.period = period; } public void approverequest(issuanceValidator validator) { if(validator.isValid(balance)) System.out.println(“Request approved..."); else System.out.println("Sorry more books are in balance..."); }}

PersonalLoanValidator Class public class issuanceValidator { public issueanceValidator() { } public boolean isValid(int balance) { if(balance>5) return true; else return false;

Task To Do In future the bank should be able to handle business type of accounts also. Identify the violation of open/close principle in classes defined. Reverse Engineered it and generate the class design of the code and create a solution with no violation of open/close principle