Difference between revisions of "OOP Class1"

esse quam videri
Jump to: navigation, search
m (Text replacement - "</csharp>" to "</syntaxhighlight>")
 
(12 intermediate revisions by 2 users not shown)
Line 5: Line 5:
 
* C# version '''Programming Language'''  https://en.wikipedia.org/wiki/C_Sharp_(programming_language)#Versions
 
* C# version '''Programming Language'''  https://en.wikipedia.org/wiki/C_Sharp_(programming_language)#Versions
 
   
 
   
* .NET Framework 4.6  
+
* .NET Framework 4.6 (now called .NET core 1)
 
* Mono http://www.mono-project.com/Main_Page
 
* Mono http://www.mono-project.com/Main_Page
  
 
==Benefits of Object Oriented Programming==
 
==Benefits of Object Oriented Programming==
*Ease of maintenance
+
 
**no more file new project most code need to be maintained for long period of time. This gets even more difficult with many authors
+
Object Oriented Programming was made for humans by humans to help deal with the complex, irrational, rigid system that is the computer. Object Oriented languages don't benefit the machine very much but they do benefit the humans that need to program the machine.
*Extend-ability
+
 
**Flexible modular clean code lasts much longer
+
*Ease of maintenance :
 +
**no more file new project most code need to be maintained for long period of time. This gets even more difficult with many authors. It's very rare to hit file-> new project in the real world
 +
*Extend-ability  
 +
**Flexible modular clean code lasts much longer. We will make a new project every week but solutions and projects are often used in a modular fashion. Groups of '''loosely coupled objects''' are one of the goals in object oriented programming
 
*Re-usability
 
*Re-usability
**please don't over engineer when you cam remember the [https://people.apache.org/~fhanik/kiss.html K.I.S.S principal]
+
**Once a proplem has been solved with OOP the solution can often be reused over and over again. One of you goals is to keep code DRY
 +
***'''D'''on't (or at least try not to)
 +
***'''R'''epeat
 +
***'''Y'''ourself
 +
**of course this concept can be stifling to begining progammers so we will also try to adhere to the
 +
***'''K'''eep
 +
***'''I'''t
 +
***'''S'''imple
 +
***'''S'''tupid
 +
**please don't over engineer when you can remember the [https://people.apache.org/~fhanik/kiss.html K.I.S.S principal]
  
 
==Introduction to Programming languages==
 
==Introduction to Programming languages==
  
  
'''Complied vs Interpreted Languages'''<br />
+
'''Complied vs Interpreted Languages''': pre-processed by compiler into machine language prior to execution<br />
'''Interpreted Languages'''<br />
+
'''Interpreted Languages''': complied at run time every time the program is executed aka a run time language<br />
  
 
Interpreted is not more human readable. It can be just as abstract ad complied code. The difference is how the machine reads and executes the code.
 
Interpreted is not more human readable. It can be just as abstract ad complied code. The difference is how the machine reads and executes the code.
Line 90: Line 102:
  
 
Hello world in C# for console really simple
 
Hello world in C# for console really simple
<syntaxhighlight lang="csharp" line="1" >
+
<syntaxhighlight lang="csharp">
 
using System;
 
using System;
 
namespace HelloClass
 
namespace HelloClass
Line 107: Line 119:
 
==Hello Console==
 
==Hello Console==
  
<csharp>using System;
+
<syntaxhighlight lang="csharp">using System;
 
using System.Collections.Generic;
 
using System.Collections.Generic;
 
using System.Linq;
 
using System.Linq;
Line 128: Line 140:
  
 
MSIL
 
MSIL
<csharp>.method public hidebysig static void  Main() cil managed
+
<syntaxhighlight lang="csharp">.method public hidebysig static void  Main() cil managed
 
{
 
{
 
   .entrypoint
 
   .entrypoint
Line 142: Line 154:
 
==Hello WinForms==
 
==Hello WinForms==
 
form1.cs
 
form1.cs
<csharp>
+
<syntaxhighlight lang="csharp">
 
using System;
 
using System;
 
using System.Collections.Generic;
 
using System.Collections.Generic;
Line 177: Line 189:
  
 
Window1.xaml.cs
 
Window1.xaml.cs
<csharp>
+
<syntaxhighlight lang="csharp">
 
using System;
 
using System;
 
using System.Collections.Generic;
 
using System.Collections.Generic;
Line 238: Line 250:
 
==Homework==
 
==Homework==
  
#Get VS2013 and install on your computer or use it in the lab
+
#Get VS2015 and install on your computer or use it in the lab. Comminity version is fine https://go.microsoft.com/fwlink/?LinkId=691978&clcid=0x409
 
#write and compile [[Helloworld in csharp]] as a c# console application '''bonus''' make hello world in something besides the console and make it interactive
 
#write and compile [[Helloworld in csharp]] as a c# console application '''bonus''' make hello world in something besides the console and make it interactive
 
#Upload a zip of hello world to moodle
 
#Upload a zip of hello world to moodle
Line 253: Line 265:
  
  
[[Category:IAM Classes]][[Category:Object Oriented Programming]]
+
[[Category:IAM Classes]]

Latest revision as of 16:24, 10 June 2019

About Class

Technologies

Benefits of Object Oriented Programming

Object Oriented Programming was made for humans by humans to help deal with the complex, irrational, rigid system that is the computer. Object Oriented languages don't benefit the machine very much but they do benefit the humans that need to program the machine.

  • Ease of maintenance :
    • no more file new project most code need to be maintained for long period of time. This gets even more difficult with many authors. It's very rare to hit file-> new project in the real world
  • Extend-ability
    • Flexible modular clean code lasts much longer. We will make a new project every week but solutions and projects are often used in a modular fashion. Groups of loosely coupled objects are one of the goals in object oriented programming
  • Re-usability
    • Once a proplem has been solved with OOP the solution can often be reused over and over again. One of you goals is to keep code DRY
      • Don't (or at least try not to)
      • Repeat
      • Yourself
    • of course this concept can be stifling to begining progammers so we will also try to adhere to the
      • Keep
      • It
      • Simple
      • Stupid
    • please don't over engineer when you can remember the K.I.S.S principal

Introduction to Programming languages

Complied vs Interpreted Languages: pre-processed by compiler into machine language prior to execution
Interpreted Languages: complied at run time every time the program is executed aka a run time language

Interpreted is not more human readable. It can be just as abstract ad complied code. The difference is how the machine reads and executes the code.

Interpreted languages read and parse the source input every time a they are executed. After each line is parsed it is converted to machine language and it is executed. Interperted languages are often referd to as scripting languages and are often good for small projects that need to be deployed quickly.

Interperated Scripting Languages are often used on the web

Common Interpreted Languages are Perl,PHP, Python and Ruby

Compiled Languages
Compiled languages use a compiler to read and parse the input source code and convert it into machine language. The output binary file is then executed. If the source changes the program needs to be recompiled. Complied programs often execute faster and add extra layer of security becuase the source is not always readily available and executable. Complied code also tends to take up less memory and system resources.


HelloWorld in several common programming languages Hello World Languages

Why .NET?

  • Discussion

.Net is a platform from Microsoft. It consists of several components. The base of the new platform is the [1] .NET framework. The .NET framework sits on top of the windows(or other operating systems like mono). The .net framework consists of the Common Language Runtime(CLR) and the Framework Class Library(FCL).


The CLR is a platform for compiling, debugging and executing .NET applications. Like java the CLR a virtual machine that can better control runtime security, memory management, and threading.

Here are some examples of the classes available in the .NET framework

*System	Contains fundamental classes and base classes that define commonly used value and reference data types, events and event handlers, interfaces, attributes, and processing exceptions.
*System.Data	Consists mostly of the classes that constitute the ADO.NET architecture. The ADO.NET architecture enables you to build components that efficiently manage data from multiple data sources. In a disconnected scenario (such as the Internet), ADO.NET provides the tools to request, update, and reconcile data in multiple tier systems. The ADO.NET architecture is also implemented in client applications, such as Windows Forms, or HTML pages created by ASP.NET.
*System.Data.Common	Contains classes shared by the .NET Framework data providers. A .NET Framework data provider describes a collection of classes used to access a data source, such as a database, in the managed space.
*System.Data.SqlClient	Encapsulates the .NET Framework Data Provider for SQL Server. The .NET Framework Data Provider for SQL Server describes a collection of classes used to access a SQL Server database in the managed space.
*System.Drawing	Provides access to GDI+ basic graphics functionality. More advanced functionality is provided in the
*System.Drawing.Drawing2D	Provides advanced 2-dimensional and vector graphics functionality. This namespace includes the gradient brushes, the Matrix class (used to define geometric transforms), and the GraphicsPath class.
*System.Drawing.Imaging	Provides advanced GDI+ imaging functionality. Basic graphics functionality is provided by the System.Drawing namespace.
*System.Web	Supplies classes and interfaces that enable browser-server communication.
*System.Web.UI	Provides classes and interfaces that allow you to create controls and pages that will appear in your Web applications as user interface on a Web page.

System.Web.UI.HtmlControls Consists of a collection of classes that allow you to create HTML server controls on a Web Forms page. HTML server controls run on the server and map directly to standard HTML tags supported by most browsers. This allows you to programmatically control the HTML elements on a Web Forms page.

*System.Web.UI.WebControls	Contains classes that allow you to create Web server controls on a Web page. Web server controls run on the server and include form controls such as buttons and text boxes. They also include special purpose controls such as a calendar. Because Web server controls run on the server, you can programmatically control these elements. Web server controls are more abstract than HTML server controls. Their object model does not necessarily reflect HTML syntax.
*System.Windows.Forms	Contains classes that support design-time configuration and behavior for Windows Forms components.

Full List with descriptions http://msdn.microsoft.com/en-us/library/ms229335.aspx

Unlike Java the Microsoft CLR supports multiple languages.

Sun and Microsoft have different programming philosophies. Java write once (in java) run anywhere. CLR write in any CLR language and run on .NET The CLR from Microsoft supports several languages.

  • C# - java like language pronounced C Sharp (the language we will use for this course)
  • VB.NET - Visual Basic .NET
  • JScript
  • J# - Microsoft's Java-language
  • third party languages (cobol,eiffel,pascal,perl) Programming Language Partners

The CLR compiles the .NET languages into MS Intermediate Language (MSIL) which is similar to java's object code. It is an intermediary step between programming language and machine code. The MSIL allows .NET to support multiple programming languages. MSIL code is further compiled by the CLR at run time into machine code. This is known as JIT compilation or Just In Time.

.NET Applications

Hello world in C# for console really simple

using System;
namespace HelloClass
{
    class HelloWorld
    {
        //All Console Apps start with Main Method
        public static void Main()
        {
                Console.WriteLine("Hello World!");
                
        }
    }
}

Hello Console

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HelloWorldConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");      //Write Hello World! to the console standard out
        }
    }
}
}


http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class1/HelloWorldConsole/HelloWorldConsole/Program.cs

MSIL

.method public hidebysig static void  Main() cil managed
{
  .entrypoint
  // Code size       11 (0xb)
  .maxstack  1
  IL_0000:  ldstr      "Hello World!"
  IL_0005:  call       void [mscorlib]System.Console::WriteLine(string)
  IL_000a:  ret
} // end of method HelloWorldConsole::Main

Fully Disassembled hello.cs

Hello WinForms

form1.cs

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

namespace HelloWorldWindowsForms
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Text = "Hello World App";  //Change the title of the form
                                            //yeah i know i could have done it in the designer

            label1.Text = "Hello World!";   //Say Hello in a Label
        }
    }
}

http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class1/HelloWorldWindowsForms/HelloWorldWindowsForms/Form1.cs

Helloworld! WPF

Window1.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace HelloWorldWpfApplication
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void Canvas_Loaded(object sender, RoutedEventArgs e)
        {
            this.Title = "Hello WPF app";
            tbHello.Text = "Hello World!";      //Say hello to wpd TexBloc
        }
    }
}

window1.xaml <xml> <Window x:Class="HelloWorldWpfApplication.Window1"

   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   Title="Window1" Height="300" Width="300">
   <Grid>
       <Canvas Loaded="Canvas_Loaded">
           <TextBlock x:Name="tbHello" Canvas.Left="100" Canvas.Top="100"></TextBlock>
       </Canvas>
       
   </Grid>

</Window>

</xml>

Other Links

ECMA C# and Common Language Infrastructure Standards
Mono - Ximian Linux .NET Copy
GotDotNet - Microsoft Site to bridge the gap between .NET team and .NET developers/students


Homework

  1. Get VS2015 and install on your computer or use it in the lab. Comminity version is fine https://go.microsoft.com/fwlink/?LinkId=691978&clcid=0x409
  2. write and compile Helloworld in csharp as a c# console application bonus make hello world in something besides the console and make it interactive
  3. Upload a zip of hello world to moodle
  4. Read c# : A beginner's Tutorial Chapter 1,2 Quiz http://emils.lib.colum.edu/login?url=http://proquest.safaribooksonline.com/?uiCode=&xmlId=9780980839630
    1. Quiz in moodle on reading
  5. https://www.microsoftvirtualacademy.com/en-US/training-courses/c-fundamentals-for-absolute-beginners-8295
    1. Series Introduction
    2. Installing Visual Studio Express 2013 for Windows Desktop
    3. Creating Your First C# Program
    4. Dissecting the First C# Program You Created
    5. Quick Overview of the Visual C# Express Edition IDE