IEG3080 Tutorial 3 Prepared by Ryan. Outline Object Oriented Programming Concepts Encapsulation Inheritance Polymorphism Delegation Course Project.

Slides:



Advertisements
Similar presentations
OOP Abstraction Classes Class Members: Properties & Methods Instance (object) Encapsulation Interfaces Inheritance Composition Polymorphism Using Inheritance.
Advertisements

CLASS INHERITANCE Class inheritance is about inheriting/deriving properties from another class. When inheriting a class you are inheriting the attributes.
 2007 Dr. Natheer Khasawneh. Chapter 13. Graphical User Interface Concepts: Part 1.
IEG 3080 Tutorial 2 Jack Chan. Prepared by Jack Chan, Spring 2007 Outline.Net Platform Object Oriented Concepts Encapsulation Inheritance Polymorphism.
Graphics and Multimedia Session 13 Mata kuliah: M0874 – Programming II Tahun: 2010.
1 Chapter 6: Extending classes and Inheritance. 2 Basics of Inheritance One of the basic objectives of Inheritance is code reuse If you want to extend.
CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 9 GEORGE KOUTSOGIANNAKIS Copyright: 2015 Illinois Institute of Technology/George Koutsogiannakis 1.
Session 07: C# OOP 4 Review of: Inheritance and Polymorphism. Static and dynamic type of an object. Abstract Classes. Interfaces. FEN AK - IT:
12/08/08MET CS Fall Polymorphism 10. Polymorphism Goal: Goal: Create methods that can be invoked with all object types, base as well as.
C# Programming: From Problem Analysis to Program Design1 Introduction to Windows Programming C# Programming: From Problem Analysis to Program Design 3.
C++ Polymorphism Systems Programming. Systems Programming: Polymorphism 2   Polymorphism Examples   Relationships Among Objects in an Inheritance.
PolymorphismCS-2303, C-Term Polymorphism Hugh C. Lauer Adjunct Professor (Slides include materials from The C Programming Language, 2 nd edition,
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Lecture 6: Polymorphism - The fourth pillar of OOP - 1.
LECTURE 07 Programming using C# Inheritance
1 Graphical User Interfaces Part 2 Outline Multiple Document Interface (MDI) Windows Visual Inheritance User-Defined Controls.
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.
1 Virtual Functions and Polymorphism Chapter What You Will Learn What is polymorphism? How to declare and use virtual functions for abstract classes.
1 Classes- Inheritance Multiple Inheritance It is possible to derive a new class from more than one base class. This is called Multiple Inheritance. Under.
Lecture 5 What is object-oriented programming OOP techniques How Windows Forms applications rely on OOP.
Microsoft Visual Basic 2005: Reloaded Second Edition
BIM313 – Advanced Programming Techniques Object-Oriented Programming 1.
Visual Programming Fall 2012 – FUUAST Topic: Development environment.
Chapter 11 Inheritance and Composition. Chapter Objectives Learn about inheritance Learn about subclasses and superclasses Explore how to override the.
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.
Dr Dat Tran - Week 4 Lecture Notes 1 ToolStrip Programming Graphical User Interfaces PG (7110) University of Canberra School of Information Sciences &
C++ Review Classes and Object Oriented Programming Parasol Lab, Texas A&M University.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
COS240 O-O Languages AUBG, COS dept Lecture 33 Title: C# vs. Java (GUI Programming) Reference: COS240 Syllabus.
Chapter 6 OOP: Creating Object-Oriented Programs Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
1 Classes and Controls CE-105 Spring 2007 By: Engr. Faisal ur Rehman.
CIS 3301 C# Lesson 7 Introduction to Classes. CIS 3302 Objectives Implement Constructors. Know the difference between instance and static members. Understand.
Session 04 Module 8: Abstract classes and Interface Module 9: Properties and Indexers.
1 Interfaces and Abstract Classes Chapter Objectives You will be able to: Write Interface definitions and class definitions that implement them.
1 Lecture 6: Polymorphism - The fourth pillar of OOP -
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface Creating a Multiple-Form Interface.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Copyright © 2006 Pearson Addison-Wesley. All rights reserved Learning Objectives  Inheritance  Virtual Function.
Forms and Controls Part 3 dbg --- Naming conventions, Button, Event handlers, Label.
Introduction to Object-Oriented Programming Lesson 2.
CS212: Object Oriented Analysis and Design Lecture 16: Runtime Polymorphism.
OBJECT ORIENTED PROGRAMMING. Design principles for organizing code into user-defined types Principles include: Encapsulation Inheritance Polymorphism.
Presented by Ted Higgins, SQL Server DBA An Introduction to Object – Oriented Programming.
Class Inheritance SWE 344 Internet Protocols & Client Server Programming.
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 in C++ Chapter 7 Dynamic Binding.
CSC241 Object-Oriented Programming (OOP) Lecture No. 17.
OOP, Inheritance and Polymorphism Lecture 6. Object relations  Inheritance is ‘a kind of’, ‘a type of’ e.g. a revolver is a type of gun  Aggregation.
Learning Plan 6 Java Programming Intro to Object Oriented Programming.
Chapter 12: Support for Object- Oriented Programming Lecture # 18.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Lecture 12 Inheritance.
Classes and Inheritance
Ch 10- Advanced Object-Oriented Programming Features
Polymorphism.
Reference: COS240 Syllabus
Inheritance B.Ramamurthy 11/7/2018 B.Ramamurthy.
OOP’S Concepts in C#.Net
One class is an extension of another.
Learning Objectives Inheritance Virtual Function.
Java Programming Language
Polymorphism Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition, by Kernighan.
How to organize and document your classes
Lecture 10 Concepts of Programming Languages
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
C++ Object Oriented 1.
Lecture 6: Polymorphism
Static Binding Static binding chooses the function in the class of the base class pointer, ignoring any versions in the class of the object actually.
Presentation transcript:

IEG3080 Tutorial 3 Prepared by Ryan

Outline Object Oriented Programming Concepts Encapsulation Inheritance Polymorphism Delegation Course Project

OOP Concepts - Inheritance More about Inheritance Interface Reuse Program to an interface, not an implementation Abstract Class  Cannot be instantiated  May have some implementations Interface  Cannot be instantiated  Purely interface, does not contain implementation

OOP Concepts - Inheritance Abstract Class Represent a base class, but not want to create a object of this class Its member can be abstract or not abstract be static (not for an abstract method) have different access modifiers (e.g. public, protected)  An abstract method cannot be private

OOP Concepts - Inheritance Multiple Inheritance  Diamond Problem Solution: Use Interface DerivedClass BaseClass2 Print() BaseClass1 Print() DerivedClass dc = new DerivedClass; dc.Print(); BaseClass1’s Print() or BaseClass2’s Print() ??

OOP Concepts - Inheritance Interface Its members are all public All members must override to its derived class A class can inherit one or more interfaces, but only one (abstract) class

OOP Concepts - Inheritance abstract class MyAbsClass { abstract protected void AbsMethod(); public void ImpMethod() { Console.WriteLine(“Run”); } interface IMyInterface1 { void Interface1Method(); } Interface IMyInterface2 { void Interface2Method(); } class MyClass : MyAbsClass, IMyInterface1, IMyInterface2 { public MyClass(){} public override void AbsMethod() { Console.WriteLine(“AbsMethod”); } public void Interface1Method { Console.WriteLine(“Interface1Method”); } public void Interface2Method { Console.WriteLine(“Interface2Method”); } multiple interfaces abstract class implementation no implementation in interface

OOP Concepts - Polymorphism One Interface, Different implementations Interface  Speak() in class Animal Implementation  Speak() in class Dog and Cat Animal Speak() Dog Speak() Cat Speak()

OOP Concepts - Polymorphism class Animal { public virtual void Speak() { Console.WriteLine(“Animal”); } class Dog : Animal { public override void Speak() { Console.WriteLine(“Dog”); } class Cat : Animal { public override void Speak() { Console.WriteLine(“Cat”); } class Test { public static void main() { Animal[ ] animals = new Animal[2]; animals[0] = new Dog(); animals[1] = new Cat(); foreach (Animal a in animals) { a.Speak(); } Output: Dog Cat

OOP Concepts - Polymorphism The exact method being called is determined at run-time Run-time binding Use keyword “virtual” Abstract method – implicitly virtual

Course Project Design the whole program structure before implementation Phase 1 Draw the main character Implement one bouncing ball Use a container to store the ball Deadline : 23 Feb 2007 No Plagiarism

Course Project Properties You can set the properties of the form, such as Background Colour and Text Solution Explorer You can see all the files in the project Create a “Window Application” project

Course Project The Form consists of 2.cs files Form1.cs (Right click “Form1.cs  View Code) Form1.Designer.cs

Course Project Keyword “partial” is used to split the definition of a class over 2 or more source files (“partial” can also be used for struct or interface) Form1.cs public partial class Form1 : Form Form1.Designer.cs partial class Form1

Course Project Form1.cs Write your own code here Form1.Designer.cs Generate automatically (Refer to Lecture Note P.233) InitializeComponent() Dispose()

Course Project Draw Circle Two ways 1) Override OnPaint method 2) Use Paint Event Handler public void GamePaintHandler(object sender, PaintEventArgs e) { Graphics g = e.Graphics; g.FillEllipse(Brushes.Blue, 0, 0, 10, 10); } Add in InitializeComponent() this.Paint += new System.Windows.Forms.PaintEventHandler(this.GamePaintHandler); protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; g.FillEllipse(Brushes.Blue, 0, 0, 10, 10); }

Course Project Draw Image public void GamePaintHandler(object sender, PaintEventArgs e) { Bitmap image = new Bitmap(“ball.gif”); Graphics g = e.Graphics; g.DrawImage(image, 0, 0); }

Course Project Timer Tasks can be scheduled for repeated execution at regular intervals by using Timer Examples for its usage Update the position of the ball at a constant interval Redraw the graphics at a constant interval

Course Project Properties You can set the properties of the Timer such as Enabled and Interval You should set the Enabled value to “True” to enable the Timer Drag and drop the Timer from Toolbox to the Form

Course Project Double-click the timer icon timer1_Tick() executes every “Interval” ms Add your code here