Interface Agenda 2 Declaring Interfaces Implementing Multiple Interfaces
- 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 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 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
- What is the importance of multiple document interface
- Graduation fee breakdown
- Chapter 4 section 2 declaring independence
- Come let us sing a song a song declaring we belong to jesus
- Lol declaring intent
- The passionate pupil declaring love
- Declaring the end from the beginning
- Chapter 5 lesson 4 declaring independence
- Agenda sistemica y agenda institucional
- User led through interaction via series of questions
- Office interface vs industrial interface
- Interface------------ an interface *
- Interface in java
- Multiple document interface
- Example of mimd
- Multiple baseline vs multiple probe design
- Planning and implementing crm projects
- Implement strategies management issues
- Implementing strategies management and operations issues
- Finance and accounting issues in strategy implementation
- Matching structure with strategy
- Designing and implementing brand marketing programs
- Ubmta signatories
- Teamwork and collaboration qsen
- Chapter 7 strategic management
- Low end entry level brand
- Designing and implementing brand marketing programs
- Implementation of hrd program
- Emap
- Challenges of implementing predictive analytics
- Access rights definition
- Tripod pricing strategy
- Implementing nfpa 1600 national preparedness standard
- Stages in implementing portfolio assessment
- Management issues central to strategy implementation
- Implementing firewall technologies
- Bert spector
- Project selection and portfolio management
- Implementing merchandise plans
- Implementing organizational change theory into practice
- Interface f
- Expressive interfaces
- Which is not an objective of designing interfaces?
- Interfaces inteligentes
- Joe hogan openet
- Difference between abstract classes and interfaces
- Designing interfaces and dialogues
- F-14
- Document
- Why are user interfaces hard to implement
- Property management system interfaces
- Expressive interface