C# Object Oriented Programming Concepts MIS 324 -- Professor Sandvig 11/19/2018 C# Object Oriented Programming Concepts MIS 324 Professor Sandvig
MIS 324 -- Professor Sandvig 11/19/2018 Overview OOP Benefits Terminology Creating classes Instantiating objects Constructors Dice Roll example Dog Example Summary
MIS 324 -- Professor Sandvig 11/19/2018 OOP Benefits Hide program complexity simple public interface hides complexity inside Support reusability Create modularity Reusability
OOP Benefits Legos analogy: Modular Reusable Simple interface Each piece has single purpose Reusable Pieces can be used in multiple products Simple interface Maintainable
Terminology Encapsulation Fundamental principle of OOP Code wrapped inside classes Hide implementation details Reduce complexity Provide simple interface
Abstraction Interface exposing essential features Implementation details hidden Example: Math.Pow(number, power)
MIS 324 -- Professor Sandvig 11/19/2018 Class Typically represents real-world object Person Product Shopping Cart Etc. Properties Attributes Methods actions
Object Object Instance of a class Has functionality of class
MIS 324 -- Professor Sandvig 11/19/2018 Instantiation Source: asp.netPRO
MIS 324 -- Professor Sandvig 11/19/2018 Objects Objects have properties & methods of class
MIS 324 -- Professor Sandvig 11/19/2018 Constructors Constructors set object properties during initialization Examples: Dog myDog = new Dog(“Apollo”, “male”, 28);
Defining a Class in C# See “Classes in C#” handout Random die rolls: /dice/diceRoller
MIS 324 -- Professor Sandvig 11/19/2018 Static Classes Don’t need to instantiate Typically utility-type classes Examples: Convert.ToString(33.3); DateTime.Now.ToLongDateString();
MIS 324 -- Professor Sandvig 11/19/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 11/19/2018 Summary Covered major OOP concepts/terminology Goals: Hide program complexity Support reusability Create modularity Concepts & terminology is universal