C# Object Oriented Programming Concepts MIS 324 -- Professor Sandvig 5/15/2018 C# Object Oriented Programming Concepts MIS 324 Professor Sandvig
MIS 324 -- Professor Sandvig 5/15/2018 Overview OOP Benefits Terminology Creating classes Instantiating objects Constructors Dog Example Summary
MIS 324 -- Professor Sandvig 5/15/2018 OOP Benefits Hide program complexity simple public interface hides complexity inside Support reusability Create modularity
MIS 324 -- Professor Sandvig 5/15/2018 Terminology Class Code wrapper Exposes an interface Properties (attributes) Methods Everything in .NET is a class
Terminology Object Instantiating an object Instance of a class Provides class functionality Each object has a name Destroyed when program ends Instantiating an object CarClass carObject = new CarClass();
ASP.NET Classes & Objects MIS 324 -- Professor Sandvig 5/15/2018 ASP.NET Classes & Objects NET Class library has thousands of built-in classes Organized into NameSpaces Class Library Create custom classes Reusable across multiple pages & applications
MIS 324 -- Professor Sandvig 5/15/2018 Classes Classes are central feature of OOP Use to represent real-world objects Customers Products Web Controls Textbox button
MIS 324 -- Professor Sandvig 5/15/2018 Instantiation Source: asp.netPRO
MIS 324 -- Professor Sandvig 5/15/2018 Objects Objects have properties & methods of class
MIS 324 -- Professor Sandvig 5/15/2018 Objects Static Classes Don’t need to initialize Typically utility-type classes Examples: Convert.ToString(33.3); DateTime.Now.ToLongDateString();
MIS 324 -- Professor Sandvig 5/15/2018 Constructors Constructors set object properties during initialization Examples: Dog myDog = new Dog(“Apollo”, “male”, 28);
MIS 324 -- Professor Sandvig 5/15/2018 Inheritance Objects can inherit from other objects Goal: never program anything twice Beyond scope of this course
.NET Class Library Contains thousands of class Example Data access Data collections Drawing (graphics) Web services Etc. Example SqlCommand Class
MIS 324 -- Professor Sandvig 5/15/2018 Creating Classes Classes often represent real-world objects Product, student, faculty, shopping cart “Business objects” Example: Shopping Cart Properties: Item ISBNs, titles, count Methods: add ISBN, remove ISBN, calculate total, move to Wish List, …
MIS 324 -- Professor Sandvig 5/15/2018 Creating New Classes Where: MVC Model folder MVC ViewModel folder MVC DataRepository folder Example: Dog class might be used in following applications: Dog show management software Dog kennel software Veterinarian office Usage: Dog
MIS 324 -- Professor Sandvig 5/15/2018 Creating New Classes Properties & methods
MIS 324 -- Professor Sandvig 5/15/2018 Creating New Classes Constructors Set properties when instantiating object
MIS 324 -- Professor Sandvig 5/15/2018 Summary Covered major OOP concepts/terminology Goals: Hide program complexity Support reusability Create modularity Concepts & terminology is universal