Microsoft.NET Fundamentals. Introduction Name Company affiliation Title/function Job responsibility Database & Developer experience Your expectations.

Slides:



Advertisements
Similar presentations
ITEC200 – Week03 Inheritance and Class Hierarchies.
Advertisements

Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Fall 2007CS 2251 Inheritance and Class Hierarchies Chapter 3.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
Advanced Object-Oriented Programming Features
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
C# Programming: From Problem Analysis to Program Design1 Advanced Object-Oriented Programming Features C# Programming: From Problem Analysis to Program.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
C++ fundamentals.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Lecture 5 What is object-oriented programming OOP techniques How Windows Forms applications rely on OOP.
BASE CLASSES AND INHERITANCE CHAPTER 4. Engineer Class.
11 Getting Started with C# Chapter Objectives You will be able to: 1. Say in general terms how C# differs from C. 2. Create, compile, and run a.
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
CISC6795: Spring Object-Oriented Programming: Polymorphism.
Lecture 9 Polymorphism Richard Gesick.
An Object-Oriented Approach to Programming Logic and Design
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
BIM313 – Advanced Programming Techniques Object-Oriented Programming 1.
Visual Programming Fall 2012 – FUUAST Topic: Development environment.
C# Programming Fundamentals of Object-Oriented Programming Fundamentals of Object-Oriented Programming Introducing Microsoft.NET Introducing Microsoft.NET.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Programming Pillars Introduction to Object- Oriented Programming.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
Lecture Set 11 Creating and Using Classes Part B – Class Features – Constructors, Methods, Fields, Properties, Shared Data.
Tuc Goodwin  Object and Component-Oriented Programming  Classes in C#  Scope and Accessibility  Methods and Properties  Nested.
Advanced Object- Oriented Programming Programming Right from the Start with Visual Basic.NET 1/e 14.
Chapter Eleven Classes and Objects Programming with Microsoft Visual Basic th Edition.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Object Oriented Software Development
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
08 Encapsulation and Abstraction. 2 Contents Defining Abstraction Levels of Abstraction Class as Abstraction Defining a Java Class Instantiating a Class.
 Objects versus Class  Three main concepts of OOP ◦ Encapsulation ◦ Inheritance ◦ Polymorphism  Method ◦ Parameterized ◦ Value-Returning.
Object Oriented Programming
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
Introduction to Object-Oriented Programming Lesson 2.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Classes, Interfaces and Packages
Presented by Ted Higgins, SQL Server DBA An Introduction to Object – Oriented Programming.
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
Object-Oriented Programming: Classes and Objects Chapter 1 1.
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
Internet Computing Module II. Syllabus Creating & Using classes in Java – Methods and Classes – Inheritance – Super Class – Method Overriding – Packages.
 Description of Inheritance  Base Class Object  Subclass, Subtype, and Substitutability  Forms of Inheritance  Modifiers and Inheritance  The Benefits.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
IS 350 Course Introduction. Slide 2 Objectives Identify the steps performed in the software development life cycle Describe selected tools used to design.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Modern Programming Tools And Techniques-I
C# for C++ Programmers 1.
Classes (Part 1) Lecture 3
Object-Oriented Programming: Classes and Objects
Ch 10- Advanced Object-Oriented Programming Features
Module 5: Common Type System
Chapter 3: Using Methods, Classes, and Objects
Lecture 23 Polymorphism Richard Gesick.
Java Programming Language
Lecture 22 Inheritance Richard Gesick.
Fundaments of Game Design
Abstract Classes and Interfaces
Defining Classes and Methods
Defining Classes and Methods
C++ Object Oriented 1.
Presentation transcript:

Microsoft.NET Fundamentals

Introduction Name Company affiliation Title/function Job responsibility Database & Developer experience Your expectations for the course

Facilities Class hours Building hours Parking Restrooms Meals Phones Messages Smoking Recycling

Microsoft Certification Program Exam numberExam Title Microsoft.NET Fundamentals

About This Course Audience Course Prerequisites Course Objectives

Course Outline ModulesDescription Lesson 1 Understanding Object Oriented Programming Lesson 2 Understanding Data Types and Collections Lesson 3 Understand Events and Exceptions Lesson 4 Understand Code Compilation and Deployment Lesson 5 Understanding Input/Output (IO) Classes Lesson 6 Understanding Security Lesson 7 Understanding Rackspace APIs

Remote Lab Environment - Demo Student Machine Computer name: DJ-xxx C:\ Visual Studio SQL2012 Rackspace Network Virtual Labs

Understanding Object Oriented Programming Lesson 1

Module Overview What is Object Oriented Programming Classes vs Objects Encapsulation Abstraction Inheritance Polymorphism Interfaces Namespaces Class Libraries

Objectives Skills/ConceptsMTA Exam Objectives Understanding Object Oriented Programming Understand Object Oriented Programming Concepts in the.NET Framework (2.2) Understanding Encapsulation Understand Object Oriented Programming Concepts in the.NET Framework (2.2) Understanding Inheritance Understand Object Oriented Programming Concepts in the.NET Framework (2.2) Understanding Polymorphism Understand Object Oriented Programming Concepts in the.NET Framework (2.2) Understanding Interfaces Understand Object Oriented Programming Concepts in the.NET Framework (2.2) Understanding Namespaces Understand.NET Class Hierarchies (2.1) Understand.NET Namespaces (2.3) Understanding and Creating Class Libraries Understand and Create Class Libraries (2.4)

What is Object Oriented Programming? Object-oriented programming is a programming technique that makes use of objects to abstract actions and logic. Represent code in the form of real world objects with States and Behaviors State: What is the objects current status (width, height) Behavior: What can the object do (Place Order, Delete Customer, Save)

Object State and Behavior State Properties describe the objects state (Make, Model, Color, Current Mileage, Current Speed) Behavior Methods specify an objects behaviors (Accelerate, Brake, Turn) Events typically notify other objects that a method (behavior) has been executed/completed

Objects defined by Classes A class defines a blueprint for an object. A class defines how the objects should be built and how they should behave. An object is also known as an instance of a class.

Defining a C# Class public class Person { private string _firstName; private string _lastName; public string FirstName { get { return _firstName; } set { _firstName = value; } public class Person { private string _firstName; private string _lastName; public string FirstName { get { return _firstName; } set { _firstName = value; }

Demonstration – Define a Class Create the Person class with code Create the Customer class using the class designer Create the Employee class using the class designer

Methods A method is a block of code containing a series of statements. A method defines the actions or operations supported by a class. When a method’s return type is void, a return statement with no value can be used. A method is defined by specifying: Access level Return type, Name of the method, and Optional list of parameters A block of code enclosed in braces.

Method Example The InitFields method takes two parameters and uses the parameter values to respectively assign the data fields firstName and lastName. If a return statement is not used, as in the InitFields method, the method will stop executing when it reaches the end of the code block. public void InitFields(string firstName, string lastName) { _firstName = firstName; _lastName = lastName; } public void InitFields(string firstName, string lastName) { _firstName = firstName; _lastName = lastName; }

Practice: Create a Simple Class Create a Console Application Add a class named Rectangle Add length and width Private Fields Add a Constructor Add the GetArea Method Note: Practice begins on Page 3

Constructors Constructors are special class methods that are executed when a new instance of a class is created. Constructors are used to initialize the data members of the object. Constructors must have exactly the same name as the class, and they do not have a return type. Multiple constructors, each with a unique signature, can be defined for a class.

Constructor Example public class Person { private string _firstName; private string _lastName; public Person(string firstName, string lastName, string address) : this() { _firstName = firstName; _lastName = lastName; _address = address; } public class Person { private string _firstName; private string _lastName; public Person(string firstName, string lastName, string address) : this() { _firstName = firstName; _lastName = lastName; _address = address; }

Creating Objects Objects need a template that defines how they should be built. All objects created from the same template look and behave in a similar way. class Program { static void Main(string[] args) { BusinessRules.Person objp = new BusinessRules.Person("Antoine", "Victor", "123 Elm Street"); Console.WriteLine(objp.FirstName + " " + objp.LastName + " " + objp.Address + " " + objp.City); Console.WriteLine("Press any key to exit"); Console.ReadKey(); } class Program { static void Main(string[] args) { BusinessRules.Person objp = new BusinessRules.Person("Antoine", "Victor", "123 Elm Street"); Console.WriteLine(objp.FirstName + " " + objp.LastName + " " + objp.Address + " " + objp.City); Console.WriteLine("Press any key to exit"); Console.ReadKey(); }

Practice: Create an Object Create an instance of the Rectangle class Execute the GetArea Method Page 5

Properties Class members accessed like data fields but contain code like a method. A property has two accessors, get and set. Get accessor: Used to return the property value Set accessor: Used to assign a new value to the property.

Property Example public class Person { private string _firstName; public string FirstName { get { return _firstName; } set { _firstName = value; } } public class Person { private string _firstName; public string FirstName { get { return _firstName; } set { _firstName = value; } }

Practice: Create a Property Add Length and Width Properties to the Rectangle Class Modify the Console application to set Length and Width Properties Run the Console Application Note: Practice begins on page 6

The this Keyword The this keyword is a reference to the current instance of the class. You can use the this keyword to refer to any member of the current object. public class Person { private string _firstName; private string _lastName; public Person(string firstName, string lastName, string address) : this() { this._firstName = firstName; this._lastName = lastName; this._address = address; } public class Person { private string _firstName; private string _lastName; public Person(string firstName, string lastName, string address) : this() { this._firstName = firstName; this._lastName = lastName; this._address = address; }

Static Members The static keyword is used to declare members that do not belong to individual objects but to a class itself. When an instance of a class is created, a separate copy is created for each instance field, but only one copy of a static field is shared by all instances. A static member cannot be referenced through an instance object. Instead, a static member is referenced through the class name.

Static Member Example class Program { static void Main(string[] args) { Console.WriteLine(Person.UserType); } public class Person { public static string UserType { get { return “Person”; } } class Program { static void Main(string[] args) { Console.WriteLine(Person.UserType); } public class Person { public static string UserType { get { return “Person”; } }

Practice: Create a Static member Add a Static Method to the Rectangle class Modify the Console Application to call the Static Method Page 10

Encapsulation Encapsulation is a mechanism to restrict access to a class or class members in order to hide design decisions that are likely to change. Access modifiers control where a type or type member can be used. Access modifierDescription publicAccess is not restricted. privateAccess is restricted to the containing class. protectedAccess is restricted to the containing class and to any class that is derived directly or indirectly from the containing class. internalAccess is restricted to the code in the same assembly. protected internal \ A combination of protected and internal—that is, access is restricted to any code in the same assembly and only to derived classes in another assembly

Abstraction Abstraction to hide complexity by exposing only that which is necessary for interaction with an object. To expose simple method names that allow object interaction without exposing the internal functionality of the class Abstraction and Encapsulation are complementary concepts.

Inheritance Inheritance is an OOP feature that allows you to develop a class once, and then reuse that code over and over as the basis of new classes. The class whose functionality is inherited is called a base class. The class that inherits the functionality is called a derived class A derived class can also define additional features that make it different from the base class. Unlike classes, the structs do not support inheritance.

Inheritance Example public class Person { public string Name{ get; protected set; } } public class Customer : Person { public Customer(string name) { Name = name; } public string GetName() { return Name; } public class Person { public string Name{ get; protected set; } } public class Customer : Person { public Customer(string name) { Name = name; } public string GetName() { return Name; }

Inheritance - Example

Practice: Creating Derived Classes Create a Polygon class Add Width and Length Properties to the Polygon class Remove Length and Width Properties from the Rectangle class Edit the Rectangle class to inherit from the Polygon class Run the Console Application Note: Practice begins on page 12

Abstract Classes Lowest Common Denominator Common member definitions for all derived classes Often provide incomplete implementation. Abstract / Base classes may not be instantiated directly To instantiate an abstract class Inherit from it creating a new class Complete its members implementation. Instantiate the class Set Properties Execute Methods

Abstract Class Example public abstract class Person { public string Name{ get; protected set; } } public class Customer : Person { public Customer(string name) { Name = name; } public string GetName() { return Name; } public abstract class Person { public string Name{ get; protected set; } } public class Customer : Person { public Customer(string name) { Name = name; } public string GetName() { return Name; }

Sealed Classes Provide complete functionality Cannot be used as base classes. Use the sealed keyword Represent the leaf level of the object hierarchy

Sealed Class Example public abstract class Person { public string Name{ get; protected set; } } public sealed class Customer : Person { public Customer(string name) { Name = name; } public string GetName() { return Name; } public abstract class Person { public string Name{ get; protected set; } } public sealed class Customer : Person { public Customer(string name) { Name = name; } public string GetName() { return Name; }

Inheriting from Object The Object class is the ultimate base class of all the classes in the.NET Framework. All classes in the.NET Framework inherit either directly or indirectly from the Object class.

Demonstration – Inherit a Base class Add the abstract keyword to the Person class Inherit the Person class in the Customer class Add the sealed keyword to the Customer class

Casting In C#, you can cast an object to any of its base types. All classes in the.NET Framework inherit either directly or indirectly from the Object class. Assigning a derived class object to a base class object doesn’t require any special syntax: Assigning a base class object to a derived class object must be explicitly cast: At execution time, if the value of o is not compatible with the Rectangle class, the runtime throws a System.InvalidCastException.

The is Operator To avoid runtime errors such as the InvalidCastException, the is operator can be used to check whether the cast is allowed before actually performing the cast. Here, the runtime checks the value of the object o. The cast statement is only executed if o contains a Rectangle object.

The as Operator The as operator is similar to the cast operation but, in the case of as, if the type conversion is not possible, null is returned instead of raising an exception. At runtime, if it is not possible to cast the value of variable o to a rectangle, a value of null is assigned to the variable r. No exceptions will be raised.

Polymorphism Polymorphism is the ability of derived classes to share common functionality with base classes but still define their own unique behavior. Polymorphism allows the objects of a derived class to be treated at runtime as objects of the base class. When a method is invoked at runtime, its exact type is identified, and the appropriate method is invoked from the derived class.

Polymorphism - Example Consider the following set of classes

Polymorphism - Example

The override and new Keywords The override keyword replaces a base class member in a derived class. The new keyword creates a new member of the same name in the derived class and hides the base class implementation.

Demonstration – Define polymorphic method Add the Create method to the Person class Override the Create method in the Customer class Override the Create method in the Employee class

Interfaces Interfaces are used to establish contracts through which objects can interact with each other without knowing the implementation details. An interface definition cannot consist of any data fields or any implementation details such as method bodies. A common interface defined in the System namespace is the IComparable namespace. This is a simple interface defined as follows: Each class that implements IComparable is free to provide its own custom comparison logic inside the CompareTo method.

Namespaces A namespace is a language element that allows you to organize code and create globally unique class names. The.NET Framework uses namespaces to organize all its classes. The System namespace groups all the fundamental classes. The System.Data namespace organizes classes for data access. The System.Web namespace is used for Web-related classes.

Class Libraries A class library is a collection of functionality defined in terms of classes, interfaces and other types that can be reused to create applications, components, and controls. Namespace enables you to organize classes into logical grouping. A namespace can span over one or more assemblies. An assembly specifies which code goes into which file on the disk. When packaging code, you should carefully plan to package related functionality together and unrelated functionality in separate assemblies.

Demonstrations – Add classes to Namespace Add the Person class to the Base Namespace Add the Customer and Employee class to the Person Namespace

Recap Objects Classes, methods, properties, delegates, events Namespaces Static members Values and References Encapsulation Access Modifiers Inheritance Abstract and sealed classes Casting, is and as operators Polymorphism Override and new keywords Interfaces Namespaces and class libraries

Lab 1 – Create Person classes Create the Business Rules Class Library Project Create the Person abstract base class Create the Employee class that inherits from the Person class Create the Customer class that inherits from the Person class