Interface Agenda 2 Declaring Interfaces Implementing Multiple Interfaces







![Declaring Interfaces : לדוגמה class App { static void Main(string[] args) { Sample s Declaring Interfaces : לדוגמה class App { static void Main(string[] args) { Sample s](https://slidetodoc.com/presentation_image_h/8294eeb2fdbc2e5feea4ccfd325f3ff0/image-8.jpg)




































![. NET Build-IN Interfaces class App { static void Main(string[] args) { Random rnd . NET Build-IN Interfaces class App { static void Main(string[] args) { Random rnd](https://slidetodoc.com/presentation_image_h/8294eeb2fdbc2e5feea4ccfd325f3ff0/image-45.jpg)






- Slides: 51

Interface

Agenda • • 2 Declaring Interfaces Implementing Multiple Interfaces Virtual Implementing Interface Methods. NET Build-IN Interfaces

Agenda • • 3 Declaring Interfaces Implementing Multiple Interfaces Virtual Implementing Interface Methods. NET Build-IN Interfaces


Declaring Interfaces Syntax: interface ISample { void Method 1(); float Method 2(); object Method 3(); . . . string Method. N(); int Property 1 { set; get; } event Delegate. Name Event. Name; } 5 'I ' מקובל ששם ממשק מתחיל באות

Declaring Interfaces : לדוגמה interface IPrint { void Print(); byte Num { get; } } 6

![Declaring Interfaces לדוגמה class App static void Mainstring args Sample s Declaring Interfaces : לדוגמה class App { static void Main(string[] args) { Sample s](https://slidetodoc.com/presentation_image_h/8294eeb2fdbc2e5feea4ccfd325f3ff0/image-8.jpg)
Declaring Interfaces : לדוגמה class App { static void Main(string[] args) { Sample s = new Sample(123); s. Print(); IPrint p = new Sample(45); p. Print(); } } 8







Declaring Interfaces : " מדוע ממשקים – "חוזה public interface ICnc. Machine { void Load. Blue. Print(); void Translate. Blue. Print(); void Start. Process(); } 15

Declaring Interfaces : " חוזה " – ממשקים מדוע Saw. Machine : ICnc. Machine 16 public class { public void Load. Blue. Print() {. . . } public void Translate. Blue. Print() {. . . } public void Start. Process() {. . . } }

Declaring Interfaces : " חוזה " – ממשקים מדוע Rotter : ICnc. Machine 17 public class { public void Load. Blue. Print() {. . . } public void Translate. Blue. Print() {. . . } public void Start. Process() {. . . } }

Declaring Interfaces : " חוזה " – ממשקים מדוע ICnc. Machine 18 public class Drill. Machine : { public void Load. Blue. Print() {. . . } public void Translate. Blue. Print() {. . . } public void Start. Process() {. . . } }

Declaring Interfaces : " מדוע ממשקים – "חוזה public class Carpentry. Workshop { private ICnc. Machine[] machines = new ICnc. Machine[100]; private int counter; public void Add. Machine(ICnc. Machine new_machine) { machines[counter++] = new_machine; } public void Create. Furniture() { for(int i=0; i<counter; i++) { machines[i]. Load. Blue. Print(); machines[i]. Translate. Blue. Print(); machines[i]. Start. Process(); } } 19 }

Declaring Interfaces Main : " מדוע ממשקים – "חוזה public class App { public static void Main() { Carpentry. Workshop carpentry = new Carpentry. Workshop(); carpentry. Add. Machine(new Saw. Machine()); carpentry. Add. Machine(new Drill. Machine()); carpentry. Add. Machine(new Rotter()); carpentry. Create. Furniture(); } } 20

Declaring Interfaces : " מדוע ממשקים – "חוזה : בעל המפעל יחליט להוסיף למערך הייצור מכונת אריזה חדשה public class Packing. Machine : ICnc. Machine { public void Load. Blue. Print() {. . . } public void Translate. Blue. Print(){. . . } public void Start. Process(){. . . } } 21


Agenda • • 23 Declaring Interfaces Implementing Multiple Interfaces Virtual Implementing Interface Methods. NET Build-IN Interfaces


Implementing Multiple Interfaces class Sample : IPrint , IMath {. . . public Sample() {. . . } public Sample(byte n 1, byte n 2, byte n 3) {. . . } public void Print() {. . . } public int Sum() { return m_Num 1+m_Num 2+m_Num 3; } public float Avg() { return (float)Sum()/3; } 25} : המשך


Implementing Multiple Interfaces. ממשק בעצמו יכול לרשת ממשק אחד או יותר public interface IBase. Report { void Create. Report(); void Write. Report(); void Read. Report(); } public interface ICustomers. Report: IBase. Report { void Report. By. Month(); void Report. By. Product(); void Report. By. Pr. Group(); } 27 : לדוגמה


Implementing Multiple Interfaces חייבת לממש את כל מה , מחלקה המממשת ממשק נגזר . שמוגדר הן בממשק הבסיס והן בממשק הנגזר public class Customer : Person, ICustomers. Report { private int Customer. ID; private object Purchases; public void Report. By. Month() {. . . } public void Report. By. Product() {. . . } public void Report. By. Pr. Group() {. . . } public void Create. Report() {. . . } public void Write. Report() {. . . } public void Read. Report() {. . . } } 29 : לדוגמה


Implementing Multiple Interfaces Explicitly Implementing Interface Methods 31 public interface IPrint 1 { void Print(); } public interface IPrint 2 { void Print(); } class Sample: IPrint 1, IPrint 2 { public Sample() {. . . } public Sample(int num) {. . . } void IPrint 1. Print() {. . . } void IPrint 2. Print() {. . . } } : לדוגמה

Implementing Multiple Interfaces Explicitly Implementing Interface Methods. Casting - קריאה לאחת מהמתודות מחייבת שימוש ב : לדוגמה Application 32 class { static void Main(string[] args) { Sample s = new Sample(33); ((IPrint 1)s). Print(); ((IPrint 2)s). Print(); IPrint 1 i 1 = new Sample(12); i 1. Print(); IPrint 2 i 2 = new Sample(45); i 1. Print(); } }


Agenda • • 34 Declaring Interfaces Implementing Multiple Interfaces Virtual Implementing Interface Methods. NET Build-IN Interfaces


Virtual Implementing : לדוגמה public interface IReports { void Html. Report(); void Xml. Report(); } 36

Virtual Implementing public class Base : IReports { public virtual void Html. Report() { Console. Write. Line("Base class : Report"); } public virtual void Xml. Report() { Console. Write. Line("Base class : Report"); } } 37 : המשך Generate Html Generate XML

Virtual Implementing public class Derived : Base, IReports { public override void Html. Report() { Console. Write. Line("Derived class : Html Report"); } public override void Xml. Report() { Console. Write. Line("Derived class : XML Report"); } } 38 : המשך Generate

Agenda • • 39 Declaring Interfaces Implementing Multiple Interfaces Virtual Implementing Interface Methods. NET Build-IN Interfaces





. NET Build-IN Interfaces IComparable public class Circle : IComparable {. . . // IComparable implementation public int Compare. To(object obj) { Circle c = null; if(obj is Circle) c = (Circle)obj; else return 1; return this. m_Radius - c. m_Radius; 44 } } : דוגמה
![NET BuildIN Interfaces class App static void Mainstring args Random rnd . NET Build-IN Interfaces class App { static void Main(string[] args) { Random rnd](https://slidetodoc.com/presentation_image_h/8294eeb2fdbc2e5feea4ccfd325f3ff0/image-45.jpg)
. NET Build-IN Interfaces class App { static void Main(string[] args) { Random rnd = new Random(); Circle[] arr = new Circle[10]; for(int i=0; i<10; i++) arr[i] = new Circle(rnd. Next(200), rnd. Next(50)); Console. Write. Line("Unsorted array. "); foreach (Circle c in arr) Console. Write. Line(c. Calc. Area()); Array. Sort(arr); Console. Write. Line("Sorted Array. "); foreach (Circle c in arr) Console. Write. Line(c. Calc. Area()); } } 45 IComparable : המשך


. NET Build-IN Interfaces IDisposable מחלקה המכילה משאבים לא מנוהלים תממש את הממשק public class Sample : IDisposable { public Sample(){. . . } ~Sample() {. . . } public void Do. Something() {. . . } public void Dispose() { Console. Write. Line( "Calling the Dispose Method. . . " ); Console. Write. Line( "Erasing Resources. . . " ); GC. Suppress. Finalize(this); } } 47 : לדוגמה

. NET Build-IN Interfaces IDisposable. מתבצעת בצורה ישירה או עקיפה Dispose הפעלת המתודה : צורה ישירה public class Sample. Main { static public void Main() { Sample t = new Sample(); t. Do. Something(); t. Dispose(); } } 48

. NET Build-IN Interfaces IDisposable. מתבצעת בצורה ישירה או עקיפה Dispose הפעלת המתודה public class Sample. Main { static public void Main() { using (Sample t = new Sample() ) { t. Do. Something(); } } } 49 : צורה עקיפה . Dispose ביציאה מהבלוק תופעל המתודה , מגדיר בלוק using משפט

Agenda • • 50 Declaring Interfaces Implementing Multiple Interfaces Virtual Implementing Interface Methods. NET Build-IN Interfaces

www. corner. co. il – הוצאת ספרים מקוונת Books Corner 51
DECLARING HEAVENS PEACE Luke 2 DECLARING HEAVENS PEACE
Inheritance Interfaces Inheritance Interfaces Inheritance Interfaces The Plan
Interface and Abstract Class Interfaces An interface is
Interfaces interface An interface in java is a
Interface Scratch Slide 3 Interface Scratch 1 Interface
Actuator sensor interface Aktuator sensor interface Interface actionneur
Interface Interface When you talk about the interface
Multiple Comparisons Multiple Comparisons v Multiple Range Tests
Multiple Sources Multiple Perspectives CICERO 2012 Multiple Perspectives
Multiple Linear Regression Multiple Regression In multiple regression
Declaring Independence Chapter 8 Section 1 Looking back
PROGRAMMING IN HASKELL Chapter 10 Declaring Types and
5 4 DECLARING INDEPENDENCE 8 17 Contributions of
Declaring Independence Enlightenment Philosophers Thomas Hobbes Need for
PROGRAMMING IN HASKELL Chapter 10 Declaring Types and
declaring the end from the beginning Isaiah 46
PROGRAMMING IN HASKELL Chapter 10 Declaring Types and
Declaring a Class the h file pragma once
CHAPTER 4 SECTION 2 Declaring Independence The Battles
Declaring Independence Chapter 5 Section 4 The Second
Variables in C Topics Naming Variables Declaring Variables
SPSRB Decision Brief on Declaring a Product Operational
Unit 2 The American Revolution Lesson 2 Declaring
DECLARING HIS WORK LUKE 416 192116 AND HE
Declaring Independence WHAT MOTIVATES PEOPLE TO ACT The
The Revolution Begins Patriots Declaring Independence Gain New
Unit 2 The American Revolution Lesson 2 Declaring
Variables in C Topics Naming Variables Declaring Variables
Chapter 8 Creating the Constitution After declaring independence
Variables in C Topics Naming Variables Declaring Variables
Declaring Independence Chapter 4 Section 2 War Begins
Alabama EMA The Pros and Cons of Declaring
Academic W rld 411 at Gustavus Declaring a
Variables in C Topics Naming Variables Declaring Variables
Declaring the Publication Ethics Scopus Comments Razieh Moghadam
Giving More Declaring Generosity Luke 14 25 33
Declaring Arrays Declare an array of 10 elements
Declaring Independence The States United Objectives Understand the
Declaring the Publication Ethics Scopus Comments Razieh Moghadam
Variables in C Topics Naming Variables Declaring Variables
DECLARING INDEPENDENCE THE COLONIES FORMALLY DECLARED THEIR INDEPENDENCE
Chapter 8 Creating the Constitution After declaring independence
PROGRAMMING IN HASKELL Chapter 10 Declaring Types and
1 Arrays Static Introduction Data Structures Arrays Declaring
2 Declaring PLSQL Variables Copyright 2006 Oracle All