CIS 199 Final Review.

Slides:



Advertisements
Similar presentations
Chapter 9: Using Classes and Objects. Understanding Class Concepts Types of classes – Classes that are only application programs with a Main() method.
Advertisements

Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
CSE 1302 Lecture 8 Inheritance Richard Gesick Figures from Deitel, “Visual C#”, Pearson.
ITEC200 – Week03 Inheritance and Class Hierarchies.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Object Oriented Programming & Software Engineering.
C# Programming: From Problem Analysis to Program Design1 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design 3rd Edition.
1 Chapter 6 Inheritance, Interfaces, and Abstract Classes.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Chapter 7 - Generalization/Specialization and Inheritance1 Chapter 7 Generalization/Specialization and Inheritance.
Inheritance. Types of Inheritance Implementation inheritance means that a type derives from a base type, taking all the base type’s member fields and.
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
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.
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.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
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.
Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms Inheritance and Polymorphism.
RIT Computer Science Dept. Goals l Inheritance l Modifiers: private, public, protected l Polymorphism.
OOP: Encapsulation,Abstraction & Polymorphism. What is Encapsulation Described as a protective barrier that prevents the code and data being randomly.
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Object Oriented Programming
Chapter 10: Introduction to Inheritance. Objectives Learn about the concept of inheritance Extend classes Override superclass methods Call constructors.
CIS 270—Application Development II Chapter 8—Classes and Objects: A Deeper Look.
1 COSC2007 Data Structures II Chapter 9 Class Relationships.
Coming up: Inheritance
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
Object-Oriented Programming: Inheritance and Polymorphism.
Inheritance in C++ Bryce Boe 2012/08/28 CS32, Summer 2012 B.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
C# Programming: From Problem Analysis to Program Design1 Creating Your Own Classes C# Programming: From Problem Analysis to Program Design 4th Edition.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Java Programming Fifth Edition Chapter 9 Introduction to Inheritance.
Inheritance and Polymorphism
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
OOP: Encapsulation &Abstraction
Object-Oriented Programming Concepts
Classes (Part 1) Lecture 3
Object-Oriented Programming: Inheritance
2.7 Inheritance Types of inheritance
Inheritance and Polymorphism
OBJECT ORIENTED PROGRAMMING II LECTURE 7 GEORGE KOUTSOGIANNAKIS
Microsoft Visual Basic 2005: Reloaded Second Edition
Chapter 3: Using Methods, Classes, and Objects
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Object Oriented Programming
CS 302 Week 11 Jim Williams, PhD.
Lecture 23 Polymorphism Richard Gesick.
OBJECT ORIENTED PROGRAMMING II LECTURE 8 GEORGE KOUTSOGIANNAKIS
IFS410: Advanced Analysis and Design
Lecture 22 Inheritance Richard Gesick.
Inheritance, Polymorphism, and Interfaces. Oh My
Advanced Java Topics Chapter 9
Week 6 Object-Oriented Programming (2): Polymorphism
Classes & Objects: Examples
Interfaces.
Java Inheritance.
Object-Oriented Programming: Inheritance and Polymorphism
CSCI 3328 Object Oriented Programming in C# Chapter 9: Classes and Objects: A Deeper Look UTPA – Fall 2012 This set of slides is revised from lecture.
Fundaments of Game Design
Chapter 9 Carrano Chapter 10 Small Java
Chapter 11 Inheritance and Encapsulation and Polymorphism
Jim Fawcett CSE687 – Object Oriented Design Spring 2014
CS 240 – Advanced Programming Concepts
Chengyu Sun California State University, Los Angeles
Presentation transcript:

CIS 199 Final Review

Outline Parameter to a method Accessor and Modifiers (get and set methods) Sequential Search Algorithm Overloading Class Concepts Overriding Inheritance Polymorphism Virtual Members

Parameter to a method A variable that holds data passed to a method when it is called Parameter 1 Parameter 2

How to call a value-returning method? Assign the returning value! Calling a method

Sequential Search Algorithm Looping through the array with for static void Main()         {             int search = 10;             bool found = false;             int[] values = { 3, 8, 13, 10, 7 };             for (int i = 0; i < values.Length; i++)             {                 if(search == values[i])                 {                     Console.WriteLine($"{search} found at index {i}");                     found = true;                     break;                 }             }             if (found) {                 Console.WriteLine("Search term found");             else {                 Console.WriteLine("Search term not found");             Console.Read();         }

Overloading Methods Overloading When you overload a C# method: Involves using one term to indicate diverse meanings When you overload a C# method: You write multiple methods with a shared name The compiler understands your meaning based on the arguments you use with the method Methods are overloaded correctly when they have the same identifier but different parameter lists

Method takes string as a parameter

Same method takes int as a parameter

Class Concept State       –A set of contents of an object’s instance variables Instance methods       –Methods associated with objects       –Every instance of the class has the same methods Class client or class user       –A program or class that instantiates objects of another prewritten class

Creating Instance Variables and Methods When creating a class, define both its attributes and its methods Field access modifiers       –new, public, protected, internal, private, static, read-only, and volatile Most class fields are non-static and private       –Provides the highest level of security

Creating Properties Property       –Properties enable a class to expose a public way of getting and setting values, while hiding implementation or verification code. Properties have accessors        –set accessors for setting an object’s fields        –get accessors for retrieving the stored values Read-only property        –Has only a get accessor

Accessors Both the get and the set accessor can be implemented as expression-bodied members. In this case, the get and set keywords must be present. The following example illustrates the use of expression body definitions for both accessors. Note that the return keyword is not used with the get accessor. https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/instance-constructors

Auto-implemented Accessors By using auto-implemented properties, you can simplify your code while having the C# compiler transparently provide the backing field for you. Note that the example also removes the parameterized constructor, so that SaleItem objects are now initialized with a call to the default constructor and an object initializer. https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/instance-constructors

Inheritance Inheritance enables you to create new classes that reuse, extend, and modify the behavior that is defined in other classes. The class whose members are inherited is called the base class, and the class that inherits those members is called the derived class.  Derived class “IS-A” base class Student IS-A Person “All students are a person, but not all persons are a student” Even if no base class is specified, one will be provided: Object

Inheritance The following illustration shows a class WorkItem that represents an item of work in some business process. Like all classes, it derives from System.Object and inherits all its methods. WorkItem adds five members of its own. These include a constructor, because constructors are not inherited.

Example from: https://docs. microsoft

Overriding toString()

Overriding In this example, the Square class must provide an overridden implementation of  Area because Area is inherited from the abstract ShapesClass. Overriding Area() Method  https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/override

Polymorphism Polymorphism is a Greek word that means "many-shaped" and You can use polymorphism to solve this problem in two basic steps: Create a class hierarchy in which each specific shape class derives from a common base class. Use a virtual method to invoke the appropriate method on any derived class through a single call to the base class method.

Virtual Members A derived class can override a base class member only if the base class member is declared as virtual or abstract. The derived member must use the override keyword to explicitly indicate that the method is intended to participate in virtual invocation. The following code provides an example.

Virtual Members When a derived class overrides a virtual member, that member is called even when an instance of that class is being accessed as an instance of the base class. The following code provides an example: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/abstract

Questions