Difference between revisions of "OOP Class9"

esse quam videri
Jump to: navigation, search
 
(36 intermediate revisions by 3 users not shown)
Line 1: Line 1:
[[Category:OOP]]
+
[[Category:IAM Classes]]
  
{{Anatomy of an aspx page}}
+
==PolyMorphism==
  
==Simple Aspx Page==
+
Using the least specific class to increase reuse.
  
http://iam.colum.edu/oop/classsource/class8/Aspx/hello.aspx [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class8/Aspx/hello.aspx hello.aspx]
+
==Value vs Reference Types==
  
http://iam.colum.edu/oop/classsource/class8/Aspx/hello2.aspx
+
int, float, string and most built in types are value types
[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class8/Aspx/hello2.aspx hello2.aspx]
 
  
http://iam.colum.edu/oop/classsource/class8/Aspx/Label.aspx
+
defined classes are Reference types.
[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class8/Aspx/Label.aspx Label.aspx]
 
  
In class
+
==Review Coins==
Build three hello aspx pages similar to the ones above
 
  
==Dogs on the web==
+
?'s
[http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class8/DogWeb DogWeb]
 
  
 +
==Review MotorVehicle==
  
 +
?'s
  
{{HTML and HTTP}}
+
==Motorvehicle Diagram==
  
 +
[[Oop Motorvehicle Diagram]]
  
http://iam.colum.edu/oop/classsource/class9/htmlForms.html [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class9/htmlForms.html htmlForms.html - source]
+
http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class7/MotorvehicleRace
  
==Courses on the Web==
+
==Private instance data members - accessors==
[http://iam.colum.edu/oop/browser/browser.aspx?f=/classsource/class8/StudentWeb Student Web]
+
Microsoft has stared calling private variables with accessors Properties
  
==Response Object==
+
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
  
Response.Write()
+
<syntaxhighlight lang="csharp">//private string color read/write
 +
private string color;
  
http://iam.colum.edu/oop/classsource/class10/Response/Response1.aspx
+
public string Color
[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class10/Response/Response1.aspx Response1.aspx - source]
+
{
 +
  get
 +
  {
 +
  return color;
 +
  }
 +
  set
 +
  {
 +
  color = value;
 +
  }
 +
}
  
Response.End()
+
//private string color read only
 +
private string color;
  
http://iam.colum.edu/oop/classsource/class10/Response/Response2.aspx
+
public string Color
[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class10/Response/Response2.aspx Response2.aspx - source]
+
{
 +
  get
 +
  {
 +
  return color;
 +
  }
 +
}</syntaxhighlight>
  
Response.Clear()
 
  
http://iam.colum.edu/oop/classsource/class10/Response/ResponseClear.aspx
+
Another property that is a good candidate for a private instance data member is the dogs age
[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class10/Response/ResponseClear.aspx ResponseClear.aspx - source]
 
  
Response.Flush()
+
<syntaxhighlight lang="csharp">
 +
private string age;
  
http://iam.colum.edu/oop/classsource/class10/Response/ResponseFlush.aspx
+
public int Age
[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class10/Response/ResponseFlush.aspx ResponseFlush.aspx - source]
+
{
 +
  //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;
 +
}
  
===Debugging with response object===
 
  
Using the response buffer can be extreemely usefull for debugging. Sometime you may have to setup a small debug system to help catch errors in object that do not inherit from System.UI.Page.
+
</syntaxhighlight>
  
Response.Flush()
+
==Windows forms==
  
http://iam.colum.edu/oop/classsource/class10/Response/ResponseDebug.aspx
+
===Separation of Concern===
[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class10/Response/ResponseDebug.aspx ResponseDebug.aspx - source]
+
https://en.wikipedia.org/wiki/Separation_of_concerns
  
==Home Work==
+
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.
  
Convert one of your classes to work as an aspx page.
+
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.
  
Have a nice break....
 
  
 +
http://www.csharphelp.com/archives/archive253.html
  
==Interfaces==
+
===Examaple of event handlers and classes===
 +
http://iam.colum.edu/oop/MotorvehicleRace.zip
  
Interfaces - implements or derives from
+
<syntaxhighlight lang="csharp">
 +
private void button1_Click(object sender, EventArgs e)
 +
        {
 +
            Console.WriteLine("button1 Clicked");
 +
            MessageBox.Show("button1 Clicked"); 
 +
        }
 +
</syntaxhighlight>
  
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.
+
Create a windows form with a button the uses your class.
  
You cannot create an instance of an interface.
+
<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;
  
Interfaces cannot contain any implementation.
+
namespace WindowsDog
 +
{
 +
    public partial class Form1 : Form
 +
    {
 +
        Dog fido;  //The form 'has a' dog
 +
       
 +
        public Form1()
 +
        {
 +
            InitializeComponent();
 +
            fido = new Dog();
 +
        }
  
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.
+
        private void btnBark_Click(object sender, EventArgs e)
 +
        {
 +
            lblBark.Text = fido.Bark(); //UIEvents are delegated to the model class
 +
        }
  
In order to specify that a class implements an inteface you use a : after the class name:
 
  
<csharp>public class NewDog : IWalkable</csharp>
+
       
 +
}
 +
</syntaxhighlight>
  
This means that the NewDog class implements the IWalkable interface.
+
==XAML Example==
  
Interfaces support multple inheritance.
+
Timer in XAML
 +
https://msdn.microsoft.com/en-us/library/cc189084(v=vs.95).aspx
  
<csharp>public class NewDog : IWalkable,IBark</csharp>
 
  
Now the NewDog Class promises to implement the IWalkable and the I Bark interface.
 
  
 +
==Home Work==
  
Phone interface example with single inhertance
+
Create a windows form and port your classes. The form should have UI elements (buttons, dropdown, etc) that demonstrate the use of you classes.
 
 
[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class8/phoneIFace.cs phoneIFace.cs] -source
 
 
 
Multiple interface inheritance - inherits IPhone, Cell, POTS
 
[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class8/phoneIFacePOTS.cs phoneIFacePOTS.cs] -source
 
 
 
Phone Interface UML
 
 
 
[[Image:PhoneInterface.png]]
 
 
 
===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.
 
[http://msdn2.microsoft.com/en-US/library/system.icomparable.aspx 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
 
 
 
[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class8/DogCompare/dogSimple.cs dogSimple.cs]
 
 
 
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 IComparable<br/>
 
[[Image:IComparable.png]]
 
 
 
The UML for a dog that implemets IComparable
 
 
 
[[Image:DogIComparable.png]]
 
 
 
 
 
Now here is an example of a Dog class that implements the IComparable inteface.
 
 
 
[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class8/DogCompare/dogICompare.cs dogICompare.cs]
 
 
 
===Other Resources on Interfaces===
 
 
 
[http://ia300218.us.archive.org/2/items/arsdigitac04n04/Lecture_04.html ArsDigita University Course 04: Object-oriented Program Design and Software Engineering - Lecture Notes 4]
 
 
 
[http://ia300218.us.archive.org/2/items/arsdigitac04n05/Lecture_05.html ArsDigita University Course 04: Object-oriented Program Design and Software Engineering - Lecture Notes 5]
 
 
 
 
 
 
 
==Web Forms==
 
Examples of Web Forms
 
 
 
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
 
 
 
==Persisting Data==
 
 
 
===POST and GET===
 
  
an asps page posting to itself
+
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
  
  
==Events in c# on the web==
+
Watch the Android-Studio-First-Look https://www.lynda.com/Android-tutorials/Welcome/143103/168098-4.html
 
 
Event handlers
 
 
 
OnClick
 
 
 
http://iam.colum.edu/oop/classsource/class9/events/events1.aspx
 
[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class9/events/events1.aspx events1.aspx - source]
 
 
 
OnCommand
 
 
 
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==
 
  
Make an post an catch aspx page with a form of your very own that asks questions about one of your objects.
+
You should logon to Oasis http://oasis.colum.edu First then select the training tab. Then search for 'Android-Studio-First-Look'
Use regular html form and aspx events to demostrate you class.
 
  
 +
*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.
 
  
Get and read Intro and Chapter 1 of Head Start Design Patterns
+
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