Uvod v C# Drugi del. Dedovanje Sintaksa Prirejanje in preverjanje tipov.

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Introduction to ASP.NET.
Advertisements

Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view class.
COSC 2006 Data Structures I Instructor: S. Xu URL:
Java Review Interface, Casting, Generics, Iterator.
METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
1 Lecture 11 Interfaces and Exception Handling from Chapters 9 and 10.
Attributes Programming in C# Attributes CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis.
Chapter 8 – Interfaces and Polymorphism Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.
ITEC200 – Week03 Inheritance and Class Hierarchies.
CS 4800 By Brandon Andrews.  Specifications  Goals  Applications  Design Steps  Testing.
Design Patterns in Java Appendix D UML at a Glance Summary prepared by Kirk Scott 1.
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
How Does Remote Method Invocation Work? –Systems that use RMI for communication typically are divided into two categories: clients and servers. A server.
Communication in Distributed Systems –Part 2
1 More on Arrays Arrays of objects Command line arguments The ArrayList class Javadoc Review Lecture 8 notes and L&L 7.1 – 7.2 Reading for this lecture:
CSE 332: C++ templates and generic programming I Motivation for Generic Programming in C++ We’ve looked at procedural programming –Reuse of code by packaging.
Copyright © 2003 ProsoftTraining. All rights reserved. Distributed Object Computing Using Java and CORBA.
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
Introduction to Classes SWE 344 Internet Protocols & Client Server Programming.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
1 v1.6 08/02/2006 Overview of Eclipse Lectures 1.Overview 2.Installing and Running 3.Building and Running Java Classes 4.Refactoring 5.Debugging 6.Testing.
C# Programming Fundamentals of Object-Oriented Programming Fundamentals of Object-Oriented Programming Introducing Microsoft.NET Introducing Microsoft.NET.
Copyright © Curt Hill Java Looking at our first console application in Eclipse.
Lecture :2 1.  DEFENTION : Java is a programming language expressly designed for use in the distributed environment of the Internet. It was designed.
In the name of Allah The Proxy Pattern Elham moazzen.
Module 3: Working with Components. Overview An Introduction to Key.NET Framework Development Technologies Creating a Simple.NET Framework Component Creating.
VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.
Session 08 Module 14: Generics and Iterator Module 15: Anonymous & partial class & Nullable type.
1 C# A brief overview by Jack Senechal and Bryan Powell.
Methods in Java. Program Modules in Java  Java programs are written by combining new methods and classes with predefined methods in the Java Application.
Lecture 20 April 13, Review for Exam All Exercises and Sample Code from Lectures Object Based Programming Object Oriented Programming String and.
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
1 CSC/ECE 517 Fall 2010 Lec. 3 Overview of Eclipse Lectures Lecture 2 “Lecture 0” Lecture 3 1.Overview 2.Installing and Running 3.Building and Running.
Chapter 14 Abstract Classes and Interfaces. Abstract Classes An abstract class extracts common features and functionality of a family of objects An abstract.
Module 8: Delegates and Events. Overview Delegates Multicast Delegates Events When to Use Delegates, Events, and Interfaces.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
1 Chapter 5: Defining Classes. 2 Basics of Classes An object is a member of a class type What is a class? Fields & Methods Types of variables: –Instance:
Introduction to Object-Oriented Programming Lesson 2.
Parallel Processing (CS526) Spring 2012(Week 8).  Shared Memory Architecture  Shared Memory Programming & PLs  Java Threads  Preparing the Environment.
CS212: Object Oriented Analysis and Design Lecture 19: Exception Handling.
JAVA Programming (Session 4) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
From C++ to C# Part 5. Enums Similar to C++ Similar to C++ Read up section 1.10 of Spec. Read up section 1.10 of Spec.
The Factory Method Pattern (Creational) ©SoftMoore ConsultingSlide 1.
Interfaces F What is an Interface? F Creating an Interface F Implementing an Interface F What is Marker Interface?
Topic 8Classes, Objects and Methods 1 Topic 8 l Class and Method Definitions l Information Hiding and Encapsulation l Objects and Reference Classes, Objects,
Chapter 6 - More About Problem Domain Classes1 Chapter 6 More About Problem Domain Classes.
© 2006 Pearson Addison-Wesley. All rights reserved 1-1 Chapter 1 Review of Java Fundamentals.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
Lecture 5:Interfaces and Abstract Classes Michael Hsu CSULA.
JAVA ACCESS MODIFIERS. Access Modifiers Access modifiers control which classes may use a feature. A classes features are: - The class itself - Its member.
1 Creating Objects  A variable holds either a primitive type or a reference to an object  A class name can be used as a type to declare an object reference.
9.1 CLASS (STATIC) VARIABLES AND METHODS Defining classes is only one aspect of object-oriented programming. The real power of object-oriented programming.
Lecture 10 – Polymorphism Nancy Harris with additional slides Professor Adams from Lewis & Bernstein.
Lecture 6:Interfaces and Abstract Classes Michael Hsu CSULA.
Variable Scope & Lifetime
Modern Programming Tools And Techniques-I
Inheritance and Polymorphism
Methods Attributes Method Modifiers ‘static’
Array Array is a variable which holds multiple values (elements) of similar data types. All the values are having their own index with an array. Index.
C# In many ways, C# looks similar to Java
Corresponds with Chapter 7
Java Programming Language
Conditional Statements
Java Inheritance.
Tonga Institute of Higher Education
Java Programming Language
Java Looking at our first console application in Eclipse
Creating and Using Classes
Presentation transcript:

Uvod v C# Drugi del

Dedovanje

Sintaksa

Prirejanje in preverjanje tipov

Kaste preverjenih tipov

Prekrivanje metod

Dinamično povezovanje (poenostavljeno)

Skrivanje

Dinamično povezovanje (s skrivanjem)

Fragile base class problem

Konstruktorji in dedovanje

Vidnost protected in internal

Abstraktni razredi

Abstraktne lastnosti in indekserji

Zapečateni razredi

Vmesniki (interfaces)

Sintaksa

Implementacija vmesnikov

Delo z vmesniki

Primer

Delegati in dogodki

Delegati Delegates are reference types which allow indirect calls to methods. A delegate instance holds references to some number of methods, and by invoking the delegate one causes all of these methods to be called. The usefulness of delegates lies in the fact that the functions which invoke them are blind to the underlying methods they thereby cause to run (see, for instance, the discussion of events, below).

Delegati From this brief description, it can be seen that delegates are functionally rather similar to C++'s 'function pointers'. However, it is important to bear in mind two main differences. Firstly, delegates are reference types rather than value types. Secondly, some single delegates can reference multiple methods

Delegate Declaration and Instantiation 1.1. public void realMethod (String myString)public void realMethod (String myString) 2.2. { 3.3. // method code // method code 4.4. } Each delegate is limited to referencing methods of a particular kind only. The type is indicated by the delegate declaration - the input parameters and return type given in the delegate declaration must be shared by the methods its delegate instances reference. To illustrate this: a delegate specified as below can be used to refer only to methods which have a single String input and no return value: public delegate void Print (String s);

Suppose, for instance, that a class contains the following method: public void realMethod (String myString) { // method code } Another method in this class could then instantiate the 'Print' delegate in the following way, so that it holds a reference to 'realMethod': Print delegateVariable = new Print(realMethod);

Razredi - dogodki Jezikovna podpora dogodkom Ključna beseda event nam omogoča določiti delegata, ki bo ustrezal poklicanim metodam ob nastopu nekega dogodka. public event AlarmEventHandler Alarm; Dogodek sprožimo s klicem dogodka Alarm(); Odjemalci se prijavijo na dogodek z operatorjem += eventSource.Alarm += new AlarmEventHandler(eventListener.AlarmRang);

Deklaracija delegata, prireditev metode delegatu

Prirejanje različnih metod

Creating a delegate value

Multicast delegati

Events = Special Delegate Variables

Izjeme (exceptions)

Stavek try

System.Exception

Throwing an Exception

Hierarhija izjem

Searching for a catch Clause

No Throws Clause in Method Signature

Namespaces and Assemblies

C# Namespaces vs. Java Packages

Namespaces vs. Packages (continued)

Assemblies

Kako se tvorijo assemblies

Opcije prevajalnika

Primeri prevajanj

Atributi

Atributi so deklarativni elementi jezika –pridevniki so na primer tudi deklarativni elementi –omogočajo dekoracijo elementov kode z dodatno informacijo assembly, modul, tip, član tipa, return value, parameter Atributi posplošujejo koncept deklarativnega elementa –atributi niso omejeni na vnaprej določeno množico –lahko se zmišljujemo svoje nove atribute –atributi in njihove vrednosti so dosegljivi v času prevajanja in v času izvajanja [Obsolete("This class is obsolete")] class A { public void F() {} }

Atributi

Atribut s parametri

Atributi Nekateri vnaprej definirani atributi Ime atributaOpis Browsable Vključenost lastnosti v okno lastnosti Serializable Določa naj bo razred ali struktura serializabilna Obsolete Določa, da je nek element kode zastarel Conditional Določa vključenost metode v odvisnosti od predproc. simbola

Atributi Zgled uporabe atributa Conditional #define Debug public class Debug { [Conditional("Debug")] public static void Assert(bool cond, String s) { if (!cond) { throw new AssertionException(s); } void DoSomething() {... // If Debug is not defined, the next line is // not even called Assert((x == y), “X should equal Y”);... }

Še en primer: atribut Conditional

Tvoji lastni atributi

Niti (threads)

Sodelujoče niti (participating threads)

Primer

Stanja niti

Primer za Join

Medsebojno izobčenje (sinhronizacija)

Razred Monitor

Wait in Pulse

Primer: sinhroniziran medpomnilnik

Komentarji XML

Posebni komentarji (podobno javadoc)

Primer komentirane kode

Tvorjena XML datoteka

XML oznake (XML tags)

Povzetek C#

Odprtokodni c# MCS: The Ximian C# compiler The Mono C# compiler is considered feature C# 1.0 complete at this point and mature. MCS is able to compile itself and many more C# programs (there is a test suite included that you can use). It is routinely used to compile Mono, roughly 1.7 million lines of C# code. The compiler is also fairly fast. On a IBM ThinkPad t40 it compiles 18,000 lines of C# code per second. Work on C# 2.0 has started: some pieces of it are available on the standard compiler with the -2 switch (iterators, method conversions) and some others are available on the `gmcs' branch on CVS (generics) Obtaining MCS The Mono C# compiler is part of the `mcs' module in the Mono CVS you can get it from our Anonymous CVS server, or you can get nightly download page.Anonymous CVSdownload page

Mono razhroščevalnik

Eclipse in mono