1 / 28

Introduction to OOP, C#, and Visual Studio

Introduction to OOP, C#, and Visual Studio. Ch 1, 2, 3. Object-Oriented Programming. Object Abstraction of a read-world item (e.g., car) Has attributes (e.g., size, shape, color) and behaviors (e.g., accelerates, brakes, turns) Class Blueprint for instantiating (creating) objects

lbetty
Download Presentation

Introduction to OOP, C#, and Visual Studio

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to OOP, C#, and Visual Studio Ch 1, 2, 3

  2. Object-Oriented Programming • Object • Abstraction of a read-world item (e.g., car) • Has attributes (e.g., size, shape, color) and behaviors (e.g., accelerates, brakes, turns) • Class • Blueprint for instantiating (creating) objects • Many objects may belong to the same class • User-defined, non-built-in type

  3. The OOP Trilogy • Three important OO principles • Encapsulation • Inheritance • Polymorphism

  4. Encapsulation • Attributes & behaviors encapsulated (wrapped) into objects • Information hiding • Implementation details hidden within objects • You can drive a car without knowing details of how engine, transmission really work • Modularization!

  5. Inheritance • Sub classes inherit attributes and behaviors of super class, then add more • A convertible is a car, and has some additional characteristics • Code reuse!

  6. Polymorphism • A behavior or attribute may have many (poly) forms (morph) in different sub classes • Cars with auto or manual transmissions work differently when accelerating. • Method implementing a behavior or attribute in super class may be overridden in a sub class • Extensibility!

  7. Payroll Example

  8. OO Analysis & Design • Analyze requirements, then design a solution, from OO point of view • UML (Unified Modeling Language) • A graphical modeling scheme • Prescribes several types of diagrams • Subject of BUS ADM 436

  9. Roots of C# 1973 1985 1995 2000 C C++ Java C# procedural procedural, OO OO object

  10. Procedural vs. OO Languages • Procedural • Unit of program is standalone procedure (also called function, method) • No support of classes and objects • Object-oriented • Unit of program is class for creating objects • Procedures are encapsulated inside classes • No support of standalone procedures • Hybrid, multi-paradigm

  11. C# and Visual Basic • Sister languages • Both are pure OO languages • Virtually equivalent in capabilities • Share the same .NET Framework Class Library • Mainly differ in syntax

  12. .NET and CLR • Microsoft .NET • Independent of specific language or platform • CLR (Common Language Runtime) • Similar to the Java runtime • Runs programs (written in various languages, e.g., C#, VB) pre-compiled into MSIL • Further translates MSIL into machine code for a particular platform

  13. Visual Studio .NET • Integrated Development Environment (IDE) • Supports several languages, including C# and VB • Builds console, GUI, Web-based apps

  14. Console Application Example

  15. Visual Basic Syntax ' Fig. 3.1: Welcome1.vb ' Simple Visual Basic program. Module FirstWelcome Sub Main() Console.WriteLine("Welcome to VB!") End Sub ' Main End Module ' FirstWelcome

  16. Developing a Console Application • Create a new project • Choose “Visual C#”, “Console Application” template • Edit source code • Compile (Build Solution) • Fix syntax errors, if any • Run and Debug • Fix logic errors, if any

  17. Code Explanations • Using existing classes in a namespace using System;// contains the Console class • Every application needs at least one class public class Welcome1 • More on public/non-public classes in Ch 10 • Braces { } around a block of code • Every statement ends with a ;

  18. The Main Method static void Main() • Starting point of every C# application • Every application has at least one Main • void method does not return a value • More on staticvs. non-static methods in Ch 7

  19. Escape Sequence for Special Character

  20. Another Example

  21. Variable • Reserved memory cell for storing data • Has name (identifier), type, size (determined by type), and value int number1; • Name: number1 • Type: int • Size: 4 bytes • Value: 0 (default)

  22. Identifier Naming Rules • Consists of letters, digits, underscores • Punctuation characters are not allowed • Cannot start with a digit • Cannot be a keyword, e.g., class, int • C# is case sensitive! (VB is not)

  23. Some Simple Types • bool: 1 byte, true/false • char: 2 bytes, single character • int: 4 bytes, integer • double: 8 bytes, real number • decimal: 16 bytes, monetary value • Other variants with different sizes, ranges

  24. Arithmetic Calculations

  25. Console Input/Output • Input number1 = int.Parse(Console.ReadLine()); • Convert a string input into a needed type • Output Console.WriteLine($"Sum is {sum}"); • Interpolated string begins with $ • Interpolation expressions enclosed in braces, e.g., {sum}

  26. Summary • OOP • Classes and objects • Encapsulation, inheritance, polymorphism • C# and Visual Basic • Sister languages • Visual Studio • IDE supporting several languages, including C# and Visual Basic

More Related