Object Oriented Practices

Slides:



Advertisements
Similar presentations
Object Oriented Programming
Advertisements

Object-Oriented Programming Python. OO Paradigm - Review Three Characteristics of OO Languages –Inheritance It isn’t necessary to build every class from.
CS 350 – Software Design The Bridge Pattern – Chapter 10 Most powerful pattern so far. Gang of Four Definition: Decouple an abstraction from its implementation.
General OO Concepts and Principles CSE301 University of Sunderland Harry R. Erwin, PhD.
ITEC200 – Week03 Inheritance and Class Hierarchies.
Chapter 10 Classes Continued
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
An Object-Oriented Approach to Programming Logic and Design
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 7 Slide 1 System models l Abstract descriptions of systems whose requirements are being.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Chapter 9 Object-Oriented Software Development F Software Development Process F Analyze Relationships Among Objects F Class Development F Class Design.
System models l Abstract descriptions of systems whose requirements are being analysed.
Advanced Object- Oriented Programming Programming Right from the Start with Visual Basic.NET 1/e 14.
9-Dec Dec-15  INTRODUCTION.  FEATURES OF OOP.  ORGANIZATION OF DATA & FUNCTION IN OOP.  OOP’S DESIGN.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Interfaces About Interfaces Interfaces and abstract classes provide more structured way to separate interface from implementation
Introduction to Object-Oriented Programming Lesson 2.
CSCE 240 – Intro to Software Engineering Lecture 3.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Object Oriented Programming Some Interesting Genes.
Engineering, 7th edition. Chapter 8 Slide 1 System models.
Copyright © Jim Fawcett Spring 2017
CompSci 280 S Introduction to Software Development
Sections Inheritance and Abstract Classes
Object-Oriented Programming Concepts
Virtual Function and Polymorphism
Inheritance ITI1121 Nour El Kadri.
Jim Fawcett CSE681 – SW Modeling & Analysis Fall 2014
The Object-Oriented Thought Process Chapter 1
Chapter 11 Object-Oriented Design
Copyright © by Curt Hill
Object-Oriented Programming & Design Lecture 18 Martin van Bommel
Polymorphism.
Review: Two Programming Paradigms
Object Oriented Concepts -II
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Abstract descriptions of systems whose requirements are being analysed
TIM 58 Chapter 8: Class and Method Design
Strategy Design Pattern
Chapter 6: Using Design Patterns
Object Oriented Practices
Object Oriented Practices
Lecture 22 Inheritance Richard Gesick.
Week 6 Object-Oriented Programming (2): Polymorphism
Object-Oriented Programming
Interfaces.
Advanced Programming Behnam Hatami Fall 2017.
Object Oriented Practices
Object Oriented Practices
Abstract Classes An abstract class is a kind of ghost class. It can pass along methods and variables but it can’t ever be instantiated itself. We can.
Static Class Members March 29, 2006 ComS 207: Programming I (in Java)
Object Oriented Practices
Object Oriented Practices
DEV-08: Exploring Object-oriented Programming
Polymorphism Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition, by Kernighan.
Overriding Methods & Class Hierarchies
Adapter Design Pattern
Overview of C++ Polymorphism
Inheritance and Polymorphism
Review of Previous Lesson
CS 112 Programming 2 Lecture 02 Abstract Classes & Interfaces (2)
Chapter 8 Inheritance Part 2.
CPS120: Introduction to Computer Science
Final and Abstract Classes
Lecture 10 Concepts of Programming Languages
Jim Fawcett CSE687 – Object Oriented Design Spring 2014
C++ Object Oriented 1.
Presentation transcript:

Object Oriented Practices This is the Abstract module. I’ve tested this to be 30 minutes in length for the slide deck. The code review portion should be 45 minutes. The speaker notes on the slides will detail the key concepts we want to cover in each of these slid Bill Wagner | Software Consultant James Sturtevant | Senior Technical Evangelist, Microsoft

Course Topics Object Oriented Practices 01 | Encapsulation 05 | Generics 02 | Inheritance 06 | Delegates Events and Lambdas 03 | Interfaces 07 | Functional Programming 04 | Abstract Classes 08 | Review Exercises Abstract classes combine the best and the worst of base classes and interfaces You can share some implementation, and you can create contracts that must be implemented by derived classes.

Abstract Classes Definition Bill Wagner | Software Consultant James Sturtevant | Senior Technical Evangelist

Module Topics Abstract Classes 01 | Abstract Classes Definition 02 | Guidelines: Abstract Classes 03 | Abstract Classes Practices 04 | Abstract Classes Results and Risks Abstract classes combine the best and the worst of base classes and interfaces You can share some implementation, and you can create contracts that must be implemented by derived classes.

Abstract Classes Definition Bill Wagner | Software Consultant James Sturtevant | Senior Technical Evangelist

Defining Abstract Classes An Abstract Class is a class that provides a common definition of a base class for multiple derived classes. It cannot be instantiated. It may also contain abstract methods that must be implemented by non-abstract derived classes. Read through the definition. The abstract base classes create a concept that combines both interface contracts and base classes: derived classes can inherit some implementation, and be forced to implement a contract defined in the base class. Abstract base classes may be what you need when you can’t decide between making a base class, and defining an interface. As we go through this module, we’ll expand on these distinctions to help you make the best decision.

Advantages of Abstract Base Classes Implementation Reuse Shared base class implementation for all derived classes Polymorphism Support Contract Definition Explain and discuss each of these advantages. Implementation Reuse means a smaller codebase, Polymorphism means that we can write functionality using the base class references. This means algorithms can be shared by writing the methods using only the base class methods and properties.

Language Support for Abstract Classes Classes can be defined as Abstract Abstract classes may declare abstract methods Classes that declare abstract methods *must* be Abstract The C# language (and VB.NET) provide a rich vocabulary to support abstract classes. Go over the implications of these rules.

Liskov Substitutability Principle Let Φ(x) be a property provable about objects x of type T. Then Φ(y) should be true for objects y of type S where S is a subtype of T. This applies to interfaces as well Explain this means any derived class object can be used in place of a base class object without noticing any difference. Classic violation: . Square and a Rectangle with SetWIdth and SetHeight . Circle and Ellipse when setting the radii

Guidelines: Abstract Classes Section header Let’s look at guidelines for finding and managing inheritance Bill Wagner | Software Consultant James Sturtevant | Senior Technical Evangelist

Prefer non-leaf nodes to be abstract Consider when an object can’t be instantiated But you want (or need) shared behaviour Making non-leaf nodes abstract means they can’t be installed Discussion points here: . Contrast abstract and non-abstract classes here. . Consider it a way to block unintended instantiation.

Abstract Classes Practices Section header How can we accomplish smart use of abstract classes? Bill Wagner | Software Consultant James Sturtevant | Senior Technical Evangelist

Practice: Common Abstraction / Implementation Base classes can define a common implementation Where methods have common implementation Can define contracts where there is no common implementation Carefully mix implementation and contract Discussion: The abstract base class combines abstract base classes with interfaces

Practice: Prevent incorrect Instantiations Mark any class not intended for instantiation ‘abstract’ Instances of that class cannot be created. This is one way to enforce a guideline that a class will not (or cannot) be instantiated. Consider it as a way to avoid users mis-using your design intent

Abstract Classes Results and Risks Section header Why are these practices going to help? How might they cause concern? Bill Wagner | Software Consultant James Sturtevant | Senior Technical Evangelist

Good Outcome: Natural Implementation Deriving from an Abstract Base Class should model “Is a” Deriving and overriding necessary methods should be “obvious” Implementing an interface should be “natural” Implementing an interface should be “obvious” Corollary: Implementations for interfaces should be complete. Implementations for base class should be complete. Developers that are implementing an interface should find that natural and obvious. If it is hard to figure out how to implement an interface, that might mean your contract is ambiguous and difficult. OK, those were copied. Deriving from an abstract base class should be clear, and all the appropriate behaviour should apply.

Good Outcome: Complete Implementation Interface Implementers can create Complete Implementations Never see NotImplementedException All base class functionality should apply Methods should not be considered “Does not apply here” Discussion points: . Classes shouldn’t “almost” implement an interface . Classes shouldn’t model “Almost is a”

Risk: Copied implementation This is often caused by: Contracts with too many requirements Convenience Methods in Interfaces “All in one” interface Discussion points: The larger and more complicated interfaces are, the fewer classes implement all of those members in an obvious manner.

Risk: Too Deep hierarchies This is often caused by: Too many unnecessary abstract base classes Too much granularity on classes Over complicating the design Discussion points: Since we are sharing implementation, be careful not to factor into too many small pieces.