Difference between revisions of "OOP Class9"

esse quam videri
Jump to: navigation, search
(Events in c#)
 
(47 intermediate revisions by 3 users not shown)
Line 1: Line 1:
==HTML Forms==
+
[[Category:IAM Classes]]
  
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 [http://www.faqs.org/rfcs/rfc2068.html RFC 2068] HTTP/1.1
+
==PolyMorphism==
  
Old html forms post information using forms in 2 ways with a get or a post http request.
+
Using the least specific class to increase reuse.
  
Get
+
==Value vs Reference Types==
:Get send information to the server using the URI. Limited to 1024 character in some browsers and servers.
 
  
Example
+
int, float, string and most built in types are value types
http://iam.colum.edu/oop/classsource/class9/simpleGet.html [http://iam.colum.edu/oop/gbrowser.php?file=/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.
+
defined classes are Reference types.
Since the method = get theese prarmenters will show up are query string parameters
 
  
URI and querystring parameters
+
==Review Coins==
  
URI - Universal Resource Identifier http://src.doc.ic.ac.uk/computing/internet/rfc/rfc1630.txt RFC1630
+
?'s
  
Http URI
+
==Review MotorVehicle==
<table border="1">
 
  
<th>Protcol</th><th>Host</th><th>Port</th><th>Path</th><th>File</th><th>Fragment identifier</th><th>Querystring</th>
+
?'s
  
 +
==Motorvehicle Diagram==
  
<tr>
+
[[Oop Motorvehicle Diagram]]
<td>http://</td><td>info.cern.ch</td><td>:8000</td><td>/imaginary/test/</td><td>file.html</td><td>#link</td><td>?test=yes</td>
 
</tr>
 
<table>
 
  
Post
+
http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class7/MotorvehicleRace
:Post posts the varibles in the HTTP Header.
 
  
 +
==Private instance data members - accessors==
 +
Microsoft has stared calling private variables with accessors Properties
  
 +
Private class memebers the use get and set keyword to set and retrieve data. Get and set are known as accessor methods private members are helpful when you want to also do other things when a data member is changed or change the rutern value under certain conditions. C# Programmer's Reference - Accessors http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfaccessorspg.asp. Lastly accessor also make read only and write only variables possible
  
Example
+
<syntaxhighlight lang="csharp">//private string color read/write
http://iam.colum.edu/oop/classsource/class9/simplePost.html [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class9/simplePost.html simplePost.html - source]
+
private string color;
 
<pre>
 
FirstName:
 
LastName:
 
Header Name Value HttpMethod GET
 
Connection keep-alive
 
Keep-Alive 300
 
Accept text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
 
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
 
Accept-Encoding gzip,deflate
 
Accept-Language en-us,en;q=0.5
 
Cookie ASP.NET_SessionId=ezfgw255ix0zd5yogj3eawej
 
Host imdev
 
Referer http://imdev/infod/jeff/
 
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1
 
</pre>
 
  
HTML Forms
+
public string Color
Example HTML Forms
+
{
 +
  get
 +
  {
 +
  return color;
 +
  }
 +
  set
 +
  {
 +
  color = value;
 +
  }
 +
}
  
http://iam.colum.edu/oop/classsource/class9/htmlForms.html [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class9/htmlForms.html htmlForms.html - source]
+
//private string color read only
 +
private string color;
  
==Web Forms==
+
public string Color
Examples of Web Forms
+
{
 +
  get
 +
  {
 +
  return color;
 +
  }
 +
}</syntaxhighlight>
  
http://iam.colum.edu/oop/classsource/class9/aspForms.aspx [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class9/aspForms.aspx aspForms.aspx - Source]
 
  
'''todo''' examples of all the html elements and how they react to form submits
+
Another property that is a good candidate for a private instance data member is the dogs age
  
==Persiting Data==
+
<syntaxhighlight lang="csharp">
 +
private string age;
  
===POST and GET===
+
public int Age
 +
{
 +
  //age can only be accessed with get there is no set accessor
 +
  //age must be set with HappyBirthday()
 +
  get
 +
  {
 +
  return age;
 +
  }
 +
}
  
an asps page posting to itself
+
public int HappyBirthday()
 +
{
 +
  age++;
 +
  return age;
 +
}
  
'''todo''' demostate viewstate
 
  
===Sessions===
+
</syntaxhighlight>
  
Dog examples
+
==Windows forms==
  
The first page creates a dog objects and stores it as a session variable.
+
===Separation of Concern===
 +
https://en.wikipedia.org/wiki/Separation_of_concerns
  
http://iam.colum.edu/oop/classsource/class9/dogsession/dog.aspx [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class9/dogsession/dog.aspx dog.aspx - source]
+
Keep you Moodle Object (logic)  classes and your UI Presentation classes separate. This will probably be very different from how you handled login in form in previous classes. We will try to keep all the Model login in the Model classes and UI Logic in the Form class. This will allow us to easily move the Model classes to a different UI like the Web or XAML.
  
http://iam.colum.edu/oop/classsource/class9/dogsession/dog_session_Page1.aspx [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class9/dogsession/dog_session_Page1.aspx dog_session_Page1.aspx - source]
+
Events
 +
:events from a windows form or web page are handled by event handlers. Events are raised when a user interacts with interface elements and handled by the event handlers.
  
http://iam.colum.edu/oop/classsource/class9/dogsession/dog_session_Page2.aspx [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class9/dogsession/dog_session_Page2.aspx dog_session_Page2.aspx - source]
 
  
http://iam.colum.edu/oop/classsource/class9/dogsession/dog_session_Page3.aspx [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class9/dogsession/dog_session_Page3.aspx dog_session_Page3.aspx - source]
+
http://www.csharphelp.com/archives/archive253.html
  
==Delgates==
+
===Examaple of event handlers and classes===
 +
http://iam.colum.edu/oop/MotorvehicleRace.zip
  
==Events in c#==
+
<syntaxhighlight lang="csharp">
 +
private void button1_Click(object sender, EventArgs e)
 +
        {
 +
            Console.WriteLine("button1 Clicked");
 +
            MessageBox.Show("button1 Clicked"); 
 +
        }
 +
</syntaxhighlight>
  
Event handlers
+
Create a windows form with a button the uses your class.
  
OnClick
+
<syntaxhighlight lang="csharp">
 +
using System;
 +
using System.Collections.Generic;
 +
using System.ComponentModel;
 +
using System.Data;
 +
using System.Drawing;
 +
using System.Text;
 +
using System.Windows.Forms;
  
http://iam.colum.edu/oop/classsource/class9/events/events1.aspx
+
namespace WindowsDog
[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class9/events/events1.aspx events1.aspx - source]
+
{
 +
    public partial class Form1 : Form
 +
    {
 +
        Dog fido;  //The form 'has a' dog
 +
       
 +
        public Form1()
 +
        {
 +
            InitializeComponent();
 +
            fido = new Dog();
 +
        }
  
OnCommand
+
        private void btnBark_Click(object sender, EventArgs e)
 +
        {
 +
            lblBark.Text = fido.Bark(); //UIEvents are delegated to the model class
 +
        }
 +
 
 +
 
 +
       
 +
}
 +
</syntaxhighlight>
 +
 
 +
==XAML Example==
 +
 
 +
Timer in XAML
 +
https://msdn.microsoft.com/en-us/library/cc189084(v=vs.95).aspx
  
http://iam.colum.edu/oop/classsource/class9/events/events2.aspx
 
[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class9/events/events2.aspx events2.aspx - source]
 
  
http://iam.colum.edu/oop/classsource/class9/events/events3.aspx
 
[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class9/events/events3.aspx events3.aspx - source]
 
  
 
==Home Work==
 
==Home Work==
  
Make an post an catch aspx page with a form of your very own that asks questions about one of your objects.
+
Create a windows form and port your classes. The form should have UI elements (buttons, dropdown, etc) that demonstrate the use of you classes.
 +
 
 +
Get Android Studio Installed
 +
 
 +
You wili need
 +
*Java JDK http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html I'm still using Java 7 Java 8 also should ve fine
 +
*Android Studio http://developer.android.com/sdk/installing/index.html?pkg=studio
 +
 
 +
 
 +
Watch the Android-Studio-First-Look https://www.lynda.com/Android-tutorials/Welcome/143103/168098-4.html
 +
 
 +
You should logon to Oasis http://oasis.colum.edu First then select the training tab. Then search for 'Android-Studio-First-Look'
 +
 
 +
*Section 0 Introduction
 +
*Section 1 Getting Started
 +
*Section 2 Exploring the User Interface (fine to watch next week)
 +
*Section 3 Designing and Coding (fine to watch next week)
 +
 
  
Use the form values to create a new instance of your class.
+
https://www.lynda.com/Android-tutorials/Welcome/143103/168098-4.html

Latest revision as of 16:31, 10 June 2019


PolyMorphism

Using the least specific class to increase reuse.

Value vs Reference Types

int, float, string and most built in types are value types

defined classes are Reference types.

Review Coins

?'s

Review MotorVehicle

?'s

Motorvehicle Diagram

Oop Motorvehicle Diagram

http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class7/MotorvehicleRace

Private instance data members - accessors

Microsoft has stared calling private variables with accessors Properties

Private class memebers the use get and set keyword to set and retrieve data. Get and set are known as accessor methods private members are helpful when you want to also do other things when a data member is changed or change the rutern value under certain conditions. C# Programmer's Reference - Accessors http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfaccessorspg.asp. Lastly accessor also make read only and write only variables possible

//private string color read/write
private string color;

public string Color
{
  get
  {
   return color;
  }
  set
  {
   color = value;
  }
}

//private string color read only
private string color;

public string Color
{
  get
  {
   return color;
  }
}


Another property that is a good candidate for a private instance data member is the dogs age

private string age;

public int Age
{
  //age can only be accessed with get there is no set accessor
  //age must be set with HappyBirthday()
  get
  {
   return age;
  }
}

public int HappyBirthday()
{
  age++;
  return age;
}

Windows forms

Separation of Concern

https://en.wikipedia.org/wiki/Separation_of_concerns

Keep you Moodle Object (logic) classes and your UI Presentation classes separate. This will probably be very different from how you handled login in form in previous classes. We will try to keep all the Model login in the Model classes and UI Logic in the Form class. This will allow us to easily move the Model classes to a different UI like the Web or XAML.

Events

events from a windows form or web page are handled by event handlers. Events are raised when a user interacts with interface elements and handled by the event handlers.


http://www.csharphelp.com/archives/archive253.html

Examaple of event handlers and classes

http://iam.colum.edu/oop/MotorvehicleRace.zip

private void button1_Click(object sender, EventArgs e)
        {
            Console.WriteLine("button1 Clicked");
            MessageBox.Show("button1 Clicked");   
        }

Create a windows form with a button the uses your class.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsDog
{
    public partial class Form1 : Form
    {
        Dog fido;  //The form 'has a' dog
        
        public Form1()
        {
            InitializeComponent();
            fido = new Dog();
        }

        private void btnBark_Click(object sender, EventArgs e)
        {
            lblBark.Text = fido.Bark(); //UIEvents are delegated to the model class
        }


        
}

XAML Example

Timer in XAML https://msdn.microsoft.com/en-us/library/cc189084(v=vs.95).aspx


Home Work

Create a windows form and port your classes. The form should have UI elements (buttons, dropdown, etc) that demonstrate the use of you classes.

Get Android Studio Installed

You wili need


Watch the Android-Studio-First-Look https://www.lynda.com/Android-tutorials/Welcome/143103/168098-4.html

You should logon to Oasis http://oasis.colum.edu First then select the training tab. Then search for 'Android-Studio-First-Look'

  • Section 0 Introduction
  • Section 1 Getting Started
  • Section 2 Exploring the User Interface (fine to watch next week)
  • Section 3 Designing and Coding (fine to watch next week)


https://www.lynda.com/Android-tutorials/Welcome/143103/168098-4.html