C# G 1 CSC 298 Object Oriented Programming Part 2.

Slides:



Advertisements
Similar presentations
Final and Abstract Classes
Advertisements

OOP Abstraction Classes Class Members: Properties & Methods Instance (object) Encapsulation Interfaces Inheritance Composition Polymorphism Using Inheritance.
Abstract Class and Interface
Object Oriented Programming
C++ Classes & Data Abstraction
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
SE-1020 Dr. Mark L. Hornick 1 Inheritance and Polymorphism: Abstract Classes The “not quite” classes.
Advanced Programming in Java
Sadegh Aliakbary Sharif University of Technology Fall 2010.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
Java Interfaces Overview Java Interfaces: A Definition.
Chapter 10 Classes Continued
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Inheritance using Java
Inheritance and Class Hierarchies Ellen Walker CPSC 201 Data Structures Hiram College.
2009 first semister Instructor: Abdalrahman Obidat 1 Revision 3 Instructor: Abdalrahman Obidat.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Inheritance Extending Class Functionality. Polymorphism Review Earlier in the course, we examined the topic of polymorphism. Many times in coding, we.
Chapter 2 Introducing Interfaces Summary prepared by Kirk Scott.
Inheritance in the Java programming language J. W. Rider.
Tuc Goodwin  Object and Component-Oriented Programming  Classes in C#  Scope and Accessibility  Methods and Properties  Nested.
C# F 1 CSC 298 Object Oriented Programming (Part 1)
1 Chapter 8 – Classes and Object: A Deeper Look Outline 1 Introduction 2 Implementing a Time Abstract Data Type with a Class 3 Class Scope 4 Controlling.
Programming in Java CSCI-2220 Object Oriented Programming.
Module 10: Inheritance in C#. Overview Deriving Classes Implementing Methods Using Sealed Classes Using Interfaces Using Abstract Classes.
Abstract Classes and Interfaces 5-Dec-15. Abstract methods You can declare an object without defining it: Person p; Similarly, you can declare a method.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Lecture 21 - Abstract Classes and Interface. Example Figure –Rectangle –Triangle Figure –Dimensions –Area.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Access Specifier. Anything declared public can be accessed from anywhere. Anything declared private cannot be seen outside of its class. When a member.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Presented by Ted Higgins, SQL Server DBA An Introduction to Object – Oriented Programming.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
(c) University of Washington05-1 CSC 143 Java Abstract Classes and Frameworks Reading: Ch. 11.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
INTRODUCTION TO CLASSES & OBJECTS CREATING CLASSES USING C#
Comp1004: Object Oriented Design I Abstract Classes and Interfaces.
C# for C++ Programmers 1.
Abstract classes and interfaces
A Concrete Presentation on Abstract Classes and Methods, Interfaces, and Polymorphism CSC 202.
Advanced Programming in Java
Advanced Programming in Java
Objects as a programming concept
Final and Abstract Classes
Inheritance and Polymorphism
Table of Contents Class Objects.
UML Class Diagram: class Rectangle
Instructor: Abdalrahman Obidat
Abstract classes and interfaces
Java Programming Language
Week 6 Object-Oriented Programming (2): Polymorphism
Interfaces.
Abstract Classes Page
Inheritance Inheritance is a fundamental Object Oriented concept
Polymorphism CMSC 202, Version 4/02.
Advanced Programming in Java
Fundaments of Game Design
Chapter 9 Carrano Chapter 10 Small Java
Chapter 14 Abstract Classes and Interfaces
CIS 199 Final Review.
Abstract classes and interfaces
Object Oriented Programming
Final and Abstract Classes
CSG2H3 Object Oriented Programming
Presentation transcript:

C# G 1 CSC 298 Object Oriented Programming Part 2

C# G 2 protected internal keyword  protected members are visible to any subclass even if the subclass is not in the same assembly  internal members are visible to any class within the same assembly  C# offers the combination protected internal to mean visible to any subclass anywhere and to any class within the same assembly

C# G 3 Visibility summary for class members ModifierVisibility private (or none) Class only internalAll classes within the same assembly protectedSubclasses anywhere protected internal Subclasses anywhere and all classes within the same assembly publicAll classes

C# G 4 Abstract classes  Some classes are so abstract that instances of them shouldn't even exist  What does it mean to have an instance of Animal ?  An abstract class is one that should not or can not be instantiated.   A concrete class can have instances  It may not make sense to attempt to fully implement all methods in an abstract class  What should Animal.speak() do?

C# G 5 abstract keyword  declare a method with the abstract modifier to indicate that it just a prototype. It is not implemented. It is implicitly marked virtual. It can't be marked private (since it must be overridden). public abstract void speak();  A class that contains an abstract method must be declared abstract public abstract class Animal{ public abstract void speak(); // more code }

C# G 6 Using abstract classes  An abstract class can't be instantiated.  An abstract class can contain other non abstract methods and ordinary variables  To use it, subclass it. Implement the abstract methods in the subclass  If a subclass doesn't implement all of the base class abstract methods, the subclass is also abstract and must be declared as such.  Abstract classes provides a framework to be filled in by the implementer

C# G 7 Abstract class example public abstract class Accommodation{ protected boolean vacancy; protected int NumberOfRooms; public abstract void reserveRoom(); public abstract void checkIn(); // etc... } public class Motel: Accommodation{ //must implement all of the abstract //methods of Accommodation //(if we want the class to be instantiated) //code would follow }

C# G 8 Interfaces  An interface is a purely abstract class  An interface specifies a set of methods or properties that a class must implement (unless the class is abstract)  Style: an interface name starts with an I.  Everything inside an interface is implicitly public and abstract. But it is an error to mark the interface members as such. public interface IDriveable{ bool startEngine(); void stopEngine(); bool turn(Direction dir); }

C# G 9 Using interfaces (1)  An interface defines some set of behavior for an object. Think of an interface as a badge that can be worn by a class to say "I can do that". public class Automobile: IDriveable { // implements the methods of Driveable public boolean startEngine() { if (notTooCold) engineRunning = true; // more code } // other methods }

C# G 10 Using interfaces (2)  Interface types act like class types.  Variables can be of an interface type  method parameters can be of an interface type  A method return type can be an interface type  Any object that implements the interface can fill that spot.  A class can implement as many interfaces as desired public class C: Base, I1, I2, I3 { /* class code */}  This is how C# deals with multiple inheritance (  C++)

C# G 11 Using interfaces (3)  An interface can't contain any field (  Java)  An interface can inherit from any number of interfaces. public interface I: I1, I2, I3 {/*code*/}  A concrete class that implements a interface must implement all of the methods in the interfaces of the hierarchy of that interface.