Monday, January 23, 2017

CS2 Goals

Four Pillars of Object Oriented Programming


Abstraction
Polymorphism
Inheritance
Encapsulation


SOLID Principal of Class Design


Single Responsibility
Open Close Principle
Liskov Substitution Principle
Integration Segregation Principle
Dependency Principle


DRY - Don't Repeat Yourself

How To Submit a Project

In Visual Studio, right click on the project in the solution explorer to show the menu:






This will open the file explorer in the project directory of your application.




From here move up one level in the directory to select the solution




Select both the project folder and the .sln file. Right click on the selected files for the file menu to appear. Select "Send to" then "Compressed (zipped) folder"








This will create a zip file containing the project. The zipped file is what should be submitted for grading or review.







Thursday, April 14, 2016

Additional Resources



I have had requests to provide any online resources to supplement the course work and class time.


Below are a few links I think you will find useful:


http://csharp.net-tutorials.com/

Welcome to this C# Tutorial, currently consisting of 49 articles covering all the most important C# concepts. This tutorial is primarily for new users of this great technology, and we recommend you to go through all the chapters, to get the most out of it as possible. While each chapter can be used without reading the previous chapters, some of them may reference things done in earlier chapters.


OOP Related Links:


http://csharp.net-tutorials.com/classes/abstract-classes/
http://csharp.net-tutorials.com/classes/inheritance/
http://csharp.net-tutorials.com/classes/interfaces/




http://www.csharp-station.com/Tutorial/CSharp/SmartConsoleSetup.aspx


Welcome to the C# Station Tutorial This is a set of lessons suited for beginning to intermediate programmers or anyone who would like to gain familiarity with the C# programming language. These lessons will help you get a quick head-start with C# programming.



http://www.c-sharpcorner.com/UploadFile/mkagrahari/introduction-to-object-oriented-programming-concepts-in-C-Sharp/

Introduction to Object Oriented Programming (OOP) concepts in C#: Abstraction, Encapsulation, Inheritance and Polymorphism.







Tuesday, April 12, 2016

Lesson 12

Chapter 13

Concepts: 
Exception handling
Specialized exception types (Known Exceptions)
Try Catch Finally

Exception Handling

Chapter 13


The C# language's exception handling features help you deal with any unexpected or exceptional situations that occur when a program is running. Exception handling uses the try, catch, and finally keywords to try actions that may not succeed, to handle failures when you decide that it is reasonable to do so, and to clean up resources afterward. Exceptions can be generated by the common language runtime (CLR), by the .NET Framework or any third-party libraries, or by application code. Exceptions are created by using the throw keyword.

In many cases, an exception may be thrown not by a method that your code has called directly, but by another method further down in the call stack. When this happens, the CLR will unwind the stack, looking for a method with a catch block for the specific exception type, and it will execute the first such catch block that if finds. If it finds no appropriate catch block anywhere in the call stack, it will terminate the process and display a message to the user

The basic exception handling model looks like this:

        private void DoSomething()
        {
            try
            {
            }
            catch (Exception)
            {
               
                throw;
            }
        }

We would first want to implement a couple of changes to the exception template code.  In most cases, we would need to assign a variable to the exception object so we can reference it in the exception block.

catch (Exception e)
{
              throw;
}

Using the variable "e" (commonly used to represent the exception object). Allows us to access the properties of the exception object when an exception is thrown in our code.

Typically we only want the message value but we can get the complete exception via the ToString() method.

catch (Exception e)
{
              MessageBox.Show(e.Message); //only the specific error message
              MessageBox.Show(e.ToString()); //the complete exception detail
}

Exceptions can be re-thrown. When a captured exception occurs we can either handle it or pass is back up the call stack. That is back up to the method or property that called it.

catch (Exception e)
{
              throw e;
}

The above code will take the exception and pass it back up to the calling method or property.

Known Exceptions

If you know in advance possible exceptions to your process we can implement exception handling to address specific issues

public static double DivideTwoNumber(double Value1, double Value2)
{
    try
    {
           return Value1 / Value2;
    }
    catch (DivideByZeroException e)
    {
          //Value 2 might be zero so we can trap for that possibility
          Console.WriteLine("Can't divide by zero");
          return 0;
    }
    catch (Exception e)
    {
          //If an exception occurs that is not a divide by zero exception then it is caught here
          throw e;
    }
}

In the method above we are going to capture two kinds of exceptions. If the method throws a divide by zero exception the first exception section would catch and process the exception. If the exception is not that then the second method would capture the exception. It is important to note that this kind of exception chaining should be done from the specific exception types to the more general. If the exception blocks in the code were reversed the divide exception would never be reached because the general exception block would catch them all.



Tuesday, March 29, 2016

Useful Links

http://visualstudioshortcuts.com Keyboard shortcuts supported in different versions of visual studio.

https://www.autohotkey.com/ AutoHotkey (AHK) is a free, open-source macro-creation and automation software for Windows that allows users to automate repetitive tasks.

Visual Studio Express Visual Studio Express editions provide free tools to develop applications for a specific platform, such as Windows Universal Platform applications, web sites, and Windows desktop applications

SQL Server Express Take advantage of the same powerful database engine in a version tailored for redistribution and embedding. SQL Server Express includes 10GB of storage per database, easy backup and restore to Microsoft Azure functionality, and compatibility with all editions of SQL Server and Microsoft Azure SQL Database so you can develop and deploy with confidence. Note: I recommend getting the version with the advanced tools. It contains both reporting and management studio.




Lesson 11

Chapter 12 
 
Concepts:  
Interface classes
Multiple interfaces 
Interface vs Abstraction 
 
 
Interfaces
Interfaces are contracts that define the minimum set of class capabilities. An interface looks like a class, but has no implementation. The only thing it contains are declarations of events, indexers, methods and/or properties. The reason interfaces only provide declarations is because they are inherited by classes, which must provide an implementation for each interface member declared.
 
 

     interface iVehicle
    {
        int Doors { get; set; }

        string Style { get; set; }

        void SetSpeed();
    }

 
The interface class above "iVehicle" outlines what a class that implements the interface MUST support. This is the contract.
 
    class Car : iVehicle
    {
        public int Doors
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }
        public string Style
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }
 
        public void SetSpeed()
        {
            throw new NotImplementedException();
        }
    }
 
The Car class must satisfy the requirements of the interface but is not limited to only those requirements. The Car class could implement other methods or properties not outlined in the interface. Note: When visual studio implements an interface for you it adds a NotimplementedException() exception to each code snippet it created. This is useful in preventing us from access a generated method or property before we are ready.
 
Multiple Interfaces
 
Unlike inheritance a class can implement more that one interface.
 
Lets' add an engine interface to the solution.
 
    interface iEngine
    {
        int Cylinders { get; set; }
        string FuelType { get; set; }
    }
 
We can then add this interface to the Car class by adding the iEngine interface to the car class the class must now support the engine requirements in addition to the vehicle interface.
 
    class Car : iVehicle, iEngine
    {
        public int Doors
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }
        public string Style
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }
        public void SetSpeed()
        {
            throw new NotImplementedException();
        }
        public int Cylinders
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }
        public string FuelType
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }
    }

Interfaces vs Abstraction
 
A class can only inherit from 1 abstract class at a time. A class can support (implement) many interfaces.
An abstract class can contain code as well as code requirements. An interface cannot contain any implementation
An abstract class can contain private variables and methods. An interface only contains public code. 
 
 
 
 
 

Lesson 10

Labs

Problem 1:



12.10 (Shape Hierarchy) Implement the Shape hierarchy of Fig. 11.3. Omit the Triangle and Tetrahedron classes. Each TwoDimensionalShape should contain read-only abstract property Area to calculate the area of the two-dimensional shape. Each ThreeDimensionalShape should have readonly abstract properties Area and Volume to calculate the surface area and volume, respectively, of the three-dimensional shape. Create an app that uses an array of Shape references to objects of each concrete class in the hierarchy. Display a text description of the object to which each array element refers. Also, in the loop that processes all the shapes in the array, determine whether each shape is a TwoDimensionalShape or a ThreeDimensionalShape. If a shape is a TwoDimensionalShape, display its area. If a shape is a ThreeDimensionalShape, display its area and volume.


Problem 2:

Build the following: