Document Sample
Namespace Powered By Docstoc
					   Class 6
By Driss Zouak
   Classes & Objects
   Namespaces
   Collections
   Caches
   Lab
An Object…
   Has Methods (subroutines and
   Has Properties

   Three types of relationships
       Is a
       Has a
       Uses a
OO - Relationships
   Is a
       If class B inherits from A or from a
        derived class of A, then we can say B “is
        an” A, because it is a superset of A’s
       You inherited from it. So if a Camry
        inherits from ToyotaCar, and ToyotaCar
        inherits from Car, then Camry IS A
        ToyotaCar and IS A Car
       This also means that B can be
        polymorphed in A
OO - Relationships
   Has a
       If class A has a data member of type
        class B, then we can say A “has an”
        object of class B.
       E.g.
        public class A
            private sampleObject as class B
        End class
       An object can have another object as one
        or more of its data members
       A car dealership object can have a list of
        car objects and a sales people object
OO - Relationships
   Uses a - Association
       If an object of class A can only perform
        its full set of functionality while having
        some awareness of class B, we say that
        class A uses class B.
       E.g. a method on class A requires an
        object of type class B to be passed in
       Key starts a car
       Person drives a car
       Salesperson sells a car
OO - Constructors
   Sub New()
       A special method that is called when
        Dim myHouse as House
        myHouse = new House()  now the
           constructor runs
       Doesn’t need to have no parameters,
        could have several constructors
       E.g. Sub New(newAddress as Address)
       When an object is created, i.e. New’ed, it’s
        refered to as instantiated. The object is an
        instance of the class.
OO - Overloading
   A function or subroutine can have
    multiple signatures
   Overloads must have different
    parameters and return types, for
OO - Shared
   Functions, subroutines and Properties
    that don’t require an object to be
    instantiated in order to be can have
    multiple signatures
   Like the Request, Response, Session
    and Application objects
   Allows things like counting the number
    of objects instantiated
   Also allows for controlling a central
    resource, like the HttpStream for
    sending data back to the user
OO - Shared
Public class PeopleClass
  Private shared population as integer
  Private name as string
  shared property NumberOfPeople

End class
OO – How…
   Without multiple inheritance, how do
    you get a Mazda Tribute class to have
    features of a Car class and an SUV
   Well, you can only inherit from one
    class. But you can implement many
   Difference between an interface and a
    class? An interface has no
    implementations for any properties or
OO - Interfaces
   Interfaces
       A set of properties and methods that a
        class supplies. A contract that ensures
        that the implementer will ensure provide
        all of the items listed in the interface, as
        described in the interface. A class may
        implement many interfaces, inherit from a
        class and have unique properties and
        methods of its own.
       Allows for polymorphism and no
        inheritance (because you inherit
OO – Interfaces
   Public interface car
     colour as string
     cost as integer
     owned as boolean
     function Buy(money as integer)
   End Interface
    Notice there is no identifier of the
     scope of each property or method, i.e.
     no ‘public’.
    Notice no implementation of the
     classes, so what happens in the case
     of multiple interface implementation?

Shared By:
Description: c sharp programming language lecture