Object oriented programming. Encapsulation. Polymorphism. Inheritance OOP

Similar documents
C++ (Non for C Programmer) (BT307) 40 Hours

Microsoft Visual Basic 2005: Reloaded

C++ for System Developers with Design Pattern

Chapter 5 Object-Oriented Programming

Intro to OOP Visibility/protection levels and constructors Friend, convert constructor, destructor Operator overloading a<=b a.

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

Advanced C++ Programming Workshop (With C++11, C++14, C++17) & Design Patterns

Object-Oriented Programming

C++ Inheritance and Encapsulation

02 Features of C#, Part 1. Jerry Nixon Microsoft Developer Evangelist Daren May President & Co-founder, Crank211

Object Oriented Programming. Solved MCQs - Part 2

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar

What are the characteristics of Object Oriented programming language?

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

Design Patterns. Manuel Mastrofini. Systems Engineering and Web Services. University of Rome Tor Vergata June 2011

Oops known as object-oriented programming language system is the main feature of C# which further support the major features of oops including:

Java Object Oriented Design. CSC207 Fall 2014

Object Oriented Programming. Java-Lecture 11 Polymorphism

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

Framework Fundamentals

CPS 506 Comparative Programming Languages. Programming Language

More C++ : Vectors, Classes, Inheritance, Templates

More C++ : Vectors, Classes, Inheritance, Templates. with content from cplusplus.com, codeguru.com

Object Oriented Programming in Java. Jaanus Pöial, PhD Tallinn, Estonia

Produced by. Design Patterns. MSc in Communications Software. Eamonn de Leastar

SDC Design patterns GoF

C++ Important Questions with Answers

Introduction to Programming Using Java (98-388)

Design Patterns. SE3A04 Tutorial. Jason Jaskolka

VALLIAMMAI ENGINEERING COLLEGE

Design Pattern What is a Design Pattern? Design Pattern Elements. Almas Ansari Page 1

CSCI 253. Overview. The Elements of a Design Pattern. George Blankenship 1. Object Oriented Design: Template Method Pattern. George Blankenship

Object-oriented Software Design Patterns

Design Patterns Reid Holmes

Concepts of Object-Oriented Programming. Richard Berger Johannes Kepler University Linz

Object Oriented Programming with c++ Question Bank

DOT NET Syllabus (6 Months)

CS304 Object Oriented Programming

Software Design COSC 4353/6353 D R. R A J S I N G H

Object-Oriented Programming

What is Design Patterns?

INTRODUCTION TO.NET. Domain of.net D.N.A. Architecture One Tier Two Tier Three Tier N-Tier THE COMMON LANGUAGE RUNTIME (C.L.R.)

CS201 - Introduction to Programming Glossary By

Object Oriented Paradigm

Object Oriented Methods with UML. Introduction to Design Patterns- Lecture 8

(12-1) OOP: Polymorphism in C++ D & D Chapter 12. Instructor - Andrew S. O Fallon CptS 122 (April 3, 2019) Washington State University

XII- COMPUTER SCIENCE VOL-II MODEL TEST I

DESIGN PATTERN - INTERVIEW QUESTIONS

Software Design Patterns. Background 1. Background 2. Jonathan I. Maletic, Ph.D.


Practice for Chapter 11

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

BCS THE CHARTERED INSTITUTE FOR IT. BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 5 Diploma in IT OBJECT ORIENTED PROGRAMMING

be used for more than one use case (for instance, for use cases Create User and Delete User, one can have one UserController, instead of two separate

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

C# Programming in the.net Framework

CS304 Object Oriented Programming Final Term

CS250 Final Review Questions

Inheritance. OOP components. Another Example. Is a Vs Has a. Virtual Destructor rule. Virtual Functions 4/13/2017

Inheritance and Polymorphism

Programming II (CS300)

EPL 603 TOPICS IN SOFTWARE ENGINEERING. Lab 6: Design Patterns

(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days

Design Patterns. An introduction

Study Guide to Exam 2

Short Notes of CS201

Design Patterns. (and anti-patterns)

Think of drawing/diagramming editors. ECE450 Software Engineering II. The problem. The Composite pattern

END TERM EXAMINATION

Absolute C++ Walter Savitch

Design Pattern and Software Architecture: IV. Design Pattern

CLASSES AND OBJECTS IN JAVA

Developing Microsoft.NET Applications for Windows (Visual Basic.NET)

What is Inheritance?

Get Unique study materials from

Design Pattern- Creational pattern 2015

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

What is Design Patterns?

CS-202 Introduction to Object Oriented Programming

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Modellistica Medica. Maria Grazia Pia, INFN Genova. Scuola di Specializzazione in Fisica Sanitaria Genova Anno Accademico

Design Patterns. Dr. Rania Khairy. Software Engineering and Development Tool

Friendship in Service of Testing

Classes, Objects, and OOP in Java. June 16, 2017

CS313D: ADVANCED PROGRAMMING LANGUAGE

C++11: 10 Features You Should be Using. Gordon R&D Runtime Engineer Codeplay Software Ltd.

10. Abstract Data Types

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

CSE 70 Final Exam Fall 2009

Introduction to Programming Microsoft.NET Applications with Visual Studio 2008 (C#)

And Even More and More C++ Fundamentals of Computer Science

Object Oriented Programming

Object Oriented Programming: Based on slides from Skrien Chapter 2

Polymorphism. Zimmer CSCI 330

Programming II (CS300)

Fast Introduction to Object Oriented Programming and C++

Introduction to OOP. Procedural Programming sequence of statements to solve a problem.

C++ Inheritance and Encapsulation

DESIGN PATTERNS FOR MERE MORTALS

Transcription:

OOP

Object oriented programming Polymorphism Encapsulation Inheritance OOP

Class concepts Classes can contain: Constants Delegates Events Fields Constructors Destructors Properties Methods Nested classes

Encapsulation Public The type or member can be accessed by any other code in the same assembly or another assembly that references it. Private The type or member can be accessed only by code in the same class or struct. Protected The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class. Internal The type or member can be accessed by any code in the same assembly, but not from another assembly.

Access modifiers

Access modifiers. Combined.

Access modifiers. Protected internal.

Access modifiers. Protected internal.

Access modifiers. Protected internal.

Access modifiers. Auto-property.

Access modifiers. Best practice Reasons to prefer public property over public field Serialization Reflection Testing Debugging Logging Used for data binding

Useful keywords Readonly Const declaration or in a constructor initialized at the declaration Value is set when instance is created Value is set once before compiling

Inheritance & Polymorphism No multiple inheritance in C# Classes can be inherited Interfaces can be implemented

Interfaces Can do logics Interfaces can contain: Properties Events Methods Indexers Always public Cannot be initiated directly Classes can implement one or more interfaces

Abstract classes Is a logics Can contain whatever a usual class can Cannot be initialized directly Class can inherit only one abstract class

Abstract classes vs interfaces Feature Interface Abstract class Multiple inheritance Default implementation Access Modfiers A class may inherit several interfaces. An interface cannot provide any code, just the signature. An interface cannot have access modifiers for the subs, functions, properties etc everything is assumed as public A class may inherit only one abstract class. An abstract class can provide complete, default code and/or just the details that have to be overridden. An abstract class can contain access modifiers for the subs, functions, properties

Abstract classes vs interfaces Feature Interface Abstract class Core VS Peripheral Homogeneity Speed Interfaces are used to define the peripheral abilities of a class. In other words both Human and Vehicle can inherit from a IMovable interface If various implementations only share method signatures then it is better to use Interfaces. Requires more time to find the actual method in the corresponding classes An abstract class defines the core identity of a class and there it is used for objects of the same type. If various implementations are of the same kind and use common behaviour or status then abstract class is better to use. Fast

Abstract classes vs interfaces Feature Interface Abstract class Adding functionality (Versioning) Fields and Constants If we add a new method to an Interface then we have to track down all the implementations of the interface and define implementation for the new method. No fields can be defined in interfaces If we add a new method to an abstract class then we have the option of providing default implementation and therefore all the existing code might work properly. An abstract class can have fields and constrants defined

Overriding

Overriding

Inheritance

Composition

Composition over inheritance Prefer composition over inheritance do not use a compose-always approach it's easy to change behavior on the fly with Dependency Injection / Setters with composition Inheritance is more rigid

Composition over inheritance Inheritance acid rule: Does TypeB want to expose the complete interface (all public methods no less) of TypeA such that TypeB can be used where TypeA is expected? Prefer composition Does TypeB only want only some/part of the behavior exposed by TypeA?

Multiple interfaces implementation

Implicit implementation

Explicit implementation

Explicit vs implicit implementation Implicit always public Explicit always private No virtual for explicit No abstract for explicit

Design patterns In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. A design pattern isn't a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations.

Singleton

Lazy initialization

Abstract factory

Other interesting patterns These patterns you will definitely need: - Strategy - Decorator - Prototype - Builder - Facade - Dependency injection - Mediator

Generics Powerful tool since c# 2.0 Point classes: Should contain values with floating points Should contain integer values Should log values every time the coordinates are changed

Generics

Generics

Generics with where

business, evolved.