Difference between revisions of "OOP Class12"

esse quam videri
Jump to: navigation, search
(Dymnically Adding Elements)
Line 1: Line 1:
 
[[Category:Object Oriented Programming]]
 
[[Category:Object Oriented Programming]]
==Dymnically Adding Elements==
 
  
===Array===
+
==Homework==
http://www.c-sharpcorner.com/UploadFile/Saurabh.Mishra/GenericsInC2PartI04122006074306AM/GenericsInC2PartI.aspx
 
  
Say we have an empty drop down list.
+
Create Characters class and weapons class that uses the strategy pattern
  
<pre><asp:DropDownList id="ddlCheese" autopostback="True" runat="server"  /></pre>
+
==Use Case==
  
Since we know that all Lists in the framework contain ListItems we can dynamically add a bunch of cheeses by using a for loop that creates and add ListItems.
+
http://en.wikipedia.org/wiki/Use_case
  
ListItem has several constructors
+
Diagrams
{| align="center"
 
|-
 
|Visibility || Constructor || Parameters
 
|-
 
|public || ListItem ||( )
 
|-
 
|public || ListItem ||( String text )
 
|-
 
|public || ListItem ||( String text , String value )
 
|-
 
|public || ListItem ||( String text , String value , Boolean enabled )
 
|}
 
  
<csharp>
+
http://en.wikipedia.org/wiki/Use_case_diagram
        //an array of names of cheese
+
 
        string [] aryNames = new string[5];
+
==Windows Course App Use Case==
         
+
 
        aryNames [0] = "Feta";
+
Actors
        aryNames [1] = "Colby";
+
:particiant outside of the system
        aryNames [2] = "Gruyere";
+
 
        aryNames [3] = "Edam";
+
[[Image:Actor.png]]
        aryNames [4] = "Colby";
+
 
 +
Activity
 +
:something an actor does
 +
[[Image:Activity.png]]
 +
 
 +
[[Image:Restaurant-UML-UC.png]]
 +
 
 +
Version 1 breif use case
 +
 
 +
Actor Admin
 +
 +
Course
 +
#Add a course to the system
 +
#Delete a course to the system
 +
Student
 +
#Add a student to the system
 +
#Delete a student to the system
 +
#Student add a course
 +
#Student remove a course
 +
 
 +
 
 +
[[Image:CourseUseCase.png]]
 +
 
 +
==Home work==
 +
 
 +
Finish the consumable example. Make Beverages Consumable by dogs and humans.
 +
 
 +
http://iam.colum.edu/oop/classsource/class11/ConsoleApplicationLunch.zip
 +
http://iam.colum.edu/oop/classsource/class11/Race.zip
  
        foreach (string cheeseName in aryNames)
 
        {
 
            ListItem newItem = new ListItem(cheeseName, cheeseName);  //get a new list item
 
                                                    //with i for string text and i for value
 
            ddlCheese.Items.Add(newItem); 
 
        }</csharp>
 
  
  
[http://iam.colum.edu/oop/classsource/class12/CheeseArray.aspx CheeseArray.aspx]
+
<!--
[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class12/CheeseArray.aspx - source]
 
  
===ArrayList of Objects===
+
<csharp>
 +
private void addCourseToolStripMenuItem_Click(object sender, EventArgs e)
 +
        {
 +
            AddCourse AC1 = new AddCourse();
 +
            AC1.FormClosed += new FormClosedEventHandler(AC1_FormClosed);
 +
            AC1.Show();
  
<csharp>//an arraylist of cheeses
+
        }
        Cheese Feta = new Cheese("Feta");
+
</csharp>
        Cheese Colby = new Cheese("Colby");
+
<csharp>
        Cheese Gruyere = new Cheese("Gruyere");
+
using System;
        Cheese Edam = new Cheese("Edam");
+
using System.Collections.Generic;
       
+
using System.Text;
       
+
using System.Collections;
        ArrayList alCheeses = new ArrayList();
 
        alCheeses.Add(Feta);
 
        alCheeses.Add(Colby);
 
        alCheeses.Add(Gruyere);
 
        alCheeses.Add(Edam);</csharp>
 
  
and the cheese class
+
namespace course_registration
<csharp>public class Cheese
 
 
{
 
{
     public string Name;
+
     class Course
    public  Milks MilkType;
 
    public string Region;
 
   
 
    public Cheese()
 
 
     {
 
     {
    }
+
        public string CourseName;
   
+
        public string CourseNumber;
    public Cheese(string name)
+
        public static ArrayList Courses;
    {
+
 
        this.Name = name;
+
        public Course()
    }
+
        {
   
+
            CourseName = "Empty Course";
    public enum Milks { Cows, Goats, Mix, Vegetarian }
+
            CourseNumber = "00-0000";
}</csharp>
+
        }
 +
 
 +
        public Course(string NewCourseName, string NewCourseNumber)
 +
        {
 +
            this.CourseNumber = NewCourseNumber;
 +
            this.CourseName = NewCourseName;
 +
        }
  
Then you can bind the new cheese arraylist to a dropdown box.
+
        public string About()
 +
        {
 +
            return "CourseName : " + this.CourseName + "\tCourseMumber :" + this.CourseNumber;
 +
        }
  
[http://iam.colum.edu/oop/classsource/class12/CheeseObject.aspx CheeseObject.aspx]
+
        public static void AddCourse(Course b)
[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class12/CheeseObject.aspx - source]
+
        {
 +
            if (Course.Courses == null)
 +
            {
 +
                Course.Courses = new ArrayList();
 +
            }
 +
            Course.Courses.Add(b);
 +
        }
  
===Saving the Arraylist in the Session===
+
        public static ArrayList GetCourseNames()
Wouldn't it be nice if we make our own cheese and add them to the arraylist. Here is an exmaple where you can dynamically add cheeses to the arraylist. The arraylist is preserved by saving it in a session variable between page hits. The first cheese 'Cheddar' is added to the Session in the initial page hit.
+
        {
 +
            ArrayList CourseNames = new ArrayList();
 +
            foreach(Course c in Course.Courses)
 +
            {
 +
                CourseNames.Add(c.CourseName);
 +
               
 +
            }
  
http://iam.colum.edu/oop/classsource/class12/CheeseObjectSession.aspx [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class12/CheeseObjectSession.aspx - source] 
+
            return CourseNames;
  
Final verson of the cheese saved in a session. This one added the MIlkType Enum and Uses a more abstracted  method to add the arraylist to the ListControl.
+
         
 +
        }
  
http://iam.colum.edu/oop/classsource/class12/CheeseObjectSession2.aspx [http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class12/CheeseObjectSession2.aspx - source]
+
        public static void RemoveCourse(string CourseName)
 +
        {
 +
            Course CourseToRemove = GetCourseFromCourseName(CourseName);
 +
            Course.Courses.Remove(CourseToRemove);
 +
        }
  
==HomeWork==
+
        public static Course GetCourseFromCourseName(string CourseName)
 +
        {
 +
            foreach (Course c in Courses)
 +
            {
 +
                if (c.CourseName == CourseName)
 +
                {
 +
                    return c;
 +
                }
 +
            }
 +
            return null;
 +
        }
 +
    }
 +
}
 +
</csharp>
 +
</csharp>
  
Make a web page that displays a list of all you super fun object from a collection in a list control (like a grid or a dropdown)
+
-->

Revision as of 15:05, 21 April 2011


Homework

Create Characters class and weapons class that uses the strategy pattern

Use Case

http://en.wikipedia.org/wiki/Use_case

Diagrams

http://en.wikipedia.org/wiki/Use_case_diagram

Windows Course App Use Case

Actors

particiant outside of the system

Actor.png

Activity

something an actor does

Activity.png

Restaurant-UML-UC.png

Version 1 breif use case

Actor Admin

Course
#Add a course to the system
#Delete a course to the system
Student
#Add a student to the system
#Delete a student to the system
#Student add a course
#Student remove a course


CourseUseCase.png

Home work

Finish the consumable example. Make Beverages Consumable by dogs and humans.

http://iam.colum.edu/oop/classsource/class11/ConsoleApplicationLunch.zip http://iam.colum.edu/oop/classsource/class11/Race.zip