GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Mindmap

Advance Programming 1

hon sam Chan Englisch

Mind map on Advance programming 1 C#: Windows messaging, overloading operator, static keyword and interface

Mind map: Advance programming 1 C#

Inhalt der Mindmap

Advance Programming 1

  1. Windows Messaging

    • used to communicate between operating system and application
    • C programming requires programmers learn a lot about window messaging and the code it used
    • C# allow programmmer to ignore window messages most of the time
      • when detected window message, e.g. keydown, application run keypress event handler if object has the focus on the form
    • Adv: programmer can ignore that way in which windows messages are involced in this
      • when windows detects an event, it passes the app a message
      • the event delegate matching the message is used to run any event handler connected to the event delegate
    • windows message containing 6 integers that generated by windows operating system
      • HWnd: get/set the window handle og the message
      • Msg: get/set the ID number for the msg
      • LParam: specifies the LParam field
      • WParam: get/set the WParam of the msg
      • Result: the value returned to windows in response to handling the msg
    • C# programmer do with windows messages
      • Listening for messages
        • create an overridden version of the form or the control's WinProc()
        • using a MessageFilter
      • Creating and sending message
        • SendMessage() and PostMessage()
    • Windows message processing
      • windows detects event --> generate message to store needed data -- > app has a msg loop method to keep checking new msg, remove old msg, and pass to approprate form --> form's WinProc() receive msg and pass to control --> control's WinProc() method run according to msg --> decide which control event the msg belong to --> run code on event handler
  2. Overloading operator

    • operator are pre-defined in C#, the default meaning of operator has been coded and stored in C#
      • in order to use operators with objects for special classes, programmer can overload the operator
        • by creating extra definitions of some operators for use with objects of a class
          • only apply to the class containing the code to make them work
    • operator group
      • Unary operator: change meaning of a single value can be overloaded
        • e.g  "-1" +,-,|,~,++,--,true,false
      • Binary operator: operator used with two values - can be overloaded
        • e.g "1+2" +,-,*,/,%,&,|,<<,>>
      • relational operator: can be overloaded but only as pairs
        • ==,|=,<,>,<=,>=
      • conversion operator: &&, ||, () cannot be overloaded
      • Compound assignment operators: can be overloaded, but are automatically overloaded when binary operator is overloaded
        • +=,-=,*=,/=,%=
      • =,.,?.,->,new, is, as, sizeof cannot be overloaded
    • use the operator method to overloading
      • must be public and static
      • can take only value parameters
      • Ref and out parameters are not allowed as arguments
      • e.g. public static return_type operator op (argument list)
      • should return a reference or value type and not void
      • same operator can be overloaded more than once
    • summary
      • operator overloading cannot modify the syntaz, precedence or associativity of an operator
      • user defined operator implementations are given preference over predefined implementations
      • can't return void
      • the operator overload methods can be overloaded
  3. Static Keyword

    • static class cannot be instantiated. i.e. cannot use the "new" keyword to create a var of the class type
    • access the members of the static class by using the class name itself.
    • static class can be used as a convenient container for sets of methods only operate on input parameters and not have to get / set internal instance fields
      • e.g. System.Math
    • Main feature:
      • Contains only static members
      • Cannot be instantiated
      • Is sealed
    • non-static class can contain static methods, fields, properties or events.
      • static member is always accessed by class name, not instance name
      • static member is callable even when on instance has been created
    • static methods and properties cannot access non-static fields and events and cannot access instance var of any object unless its explicitly passed in a method parameter
    • more common to declare non-static class with some static members than declare an entire class as static
    • two common use
      • keep a count of the number of objects that have been instantiated
      • store a value that must be shared among all instances
    • a field cannot be declared as static const, a const field is essentially static in its behavior, so const fields can be accessed by classname.membername notation
    • C# does not support static local variables
  4. interface

    • a way of defining a reference type that can point to objects
    • interface properties
      • contains the signatures of some methods
      • contain propseties
      • does not contain data or implementation code
    • can declare classes implement an interface
      • class MUST implement any methods and properties that the interface contains
      • the implementations must be public
    • class can implement more then one interface
      • can have any number of other methods and data member
      • PROVIDED it contains all methods and properties specified in the interface that it implement
    • interface is a contract to be met by the person writing a class
      • if a class implements an interface, need to provide the methods and properties specify in the interface
      • effect: if an object from a class that implements an interface, can point to it the interface reference and make use of methods and properties that the interface knows
  5. Delegates and events

    • Delegates are reference type which allow indirect calls to methods
    • delegate instance holds reference to some methods and invoking the delegate one causes all methods to be called
    • the usefulness of delegates lies in the fact that the functions invoke them are blind to the underlying methods they cause to run
    • can be specified in a namespace on their own or else can be specified in another class
    • delegate is limited to referencing methods of a particular kind only
      • type is indicated by the delegate declaration
    • A common use of delegates: to allow a programmer to alter the behavior of an existing method by passing the method a delegate to another method
      • the existing method will invoke the passed delegate and run whatever code the delegate points to
      • possible to make a method very flexible so that it can use methods written by another programmer
    • event is often something like a button click that happens outside the application
    • event can be set up for any class
    • when sth happen to an object, it check a public delegate to see if it point to any methods
      • as the delegate is public, it allows code in other classes to link a method to the delegate
    • event delegate in C# is with signature based on a void return type and a set of arguments
    • e.g. of event: a user's selection of a button on a graphical user interface, action trigger a number of methods to 'handle' it
    • distinguishes event and other method: event are backed by a particular 'subscription-notification' model.
    • good practice for Events
      • when raise an event, don't trigger the class's event object directly, but call a 'protected, virtual' method to trigger it
      • when event are raised it pass two objects to the subscribers. 1. reference to the class 2. instance of the system.eventargs class
      • if event not interested in pass data to subscribers, the delegate will return null to eventArgs / if event pass data, it is standard to use a specific class derives from the eventargs class to old the data
      • event can be intercept by overriding the method used to raise it

Informationen

Beschreibung
Mindmap am Advance Programming 1, erstellt von hon sam Chan am 20/06/2016.
Erstellt von
hon sam Chan
Aufrufe
0
Bewertung

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck