Difference between revisions of "OOP Class9"
(→Persiting Data) |
|||
Line 136: | Line 136: | ||
'''todo''' examples of all the html elements and how they react to form submits | '''todo''' examples of all the html elements and how they react to form submits | ||
− | == | + | ==Persisting Data== |
===POST and GET=== | ===POST and GET=== |
Revision as of 16:26, 2 November 2006
Contents
Interfaces
Interfaces - implements or derives from
An interface is a class that lacks implementation. The only thing it contains are definitions of events, indexers, methods and/or properties. The reason interfaces only provide definitions is because they are inherited by classes and structs, which must provide an implementation for each interface member defined. Since classes in c# can only be derived from one other class ( in c++ it is possible to derive from many) interfaces are used for multiple inheritance. Like abstract classes you cannot create an instance of an interface on derive from it.
You cannot create an instance of an interface.
Interfaces cannot contain any implementation.
Interfaces are basically a contract between classes. When a class implements an interface it is promising to implement the propery and method signature of that interface. This helps with abstraction and encurages polymorphism.
In order to specify that a class implements an inteface you use a : after the class name:
<csharp>public class NewDog : IWalkable</csharp>
This means that the NewDog class implements the IWalkable interface.
Interfaces support multple inheritance.
<csharp>public class NewDog : IWalkable,IBark</csharp>
Now the NewDog Class promises to implement the IWalkable and the I Bark interface.
Phone interface example with single inhertance
phoneIFace.cs -source
Multiple interface inheritance - inherits IPhone, Cell, POTS phoneIFacePOTS.cs -source
Phone Interface UML
IComparable and Polymorphism
In order to allow build in Arry type like the ArrayList to be able to Sort and Reverse your classes need to implement the IComparable Interface. System.IComparable on MSDN
After your classes implement this interface it will allow for polymorphic method like Sort and Reverse to work.
Here is an exmaple of a dog array that will not sort
This IComplare Interface has calls for a methpod called CompareTo. The CompareTo method shoudl retun an positive integerg if that the current object is grater that the object that is being compared. It should oreturn 0 is they are equal. And it should return a negative integer is the current object is less than the compared object.
The UML for a dog that implemets IComparable
Now here is an example of a Dog class that implements the IComparable inteface.
Other Resources on Interfaces
HTML Forms
Http is a staless protocol. There is mo mechanism built in to the protocol that allows the server to remeber clients or requests. An http simply responds to http verbs GET, POST, PUT, DEL, TRACE etc. contained in RFC 2068 HTTP/1.1
Old html forms post information using forms in 2 ways with a get or a post http request.
Get
- Get send information to the server using the URI. Limited to 1024 character in some browsers and servers.
Example http://iam.colum.edu/oop/classsource/class9/simpleGet.html simpleGet.html - source
The simpleGet.html pages form has the action of 'simpleGet.aspx' this mean that when the form is submitted the browser will request the 'simpleGet.aspx' with whatever parameters are in the form. Since the method = get theese prarmenters will show up are query string parameters
URI and querystring parameters
URI - Universal Resource Identifier http://src.doc.ic.ac.uk/computing/internet/rfc/rfc1630.txt RFC1630
Http URI
Protcol | Host | Port | Path | File | Fragment identifier | Querystring |
---|---|---|---|---|---|---|
http:// | info.cern.ch | :8000 | /imaginary/test/ | file.html | #link | ?test=yes |