c# programming fundamentals of object-oriented programming fundamentals of object-oriented...
TRANSCRIPT
C# Programming C# Programming Fundamentals of Object-Oriented Programming Fundamentals of Object-Oriented Programming Introducing Microsoft .NET Introducing Microsoft .NET Overview of C# Overview of C# Using Value-Type variables Using Value-Type variables Statements and Exceptions Statements and Exceptions Methods and Parameters Methods and Parameters Strings Arrays and Collections Strings Arrays and Collections C# and Object Oriented Programming C# and Object Oriented Programming Using Reference-Type Variables Using Reference-Type Variables Creating and Destroying Objects Creating and Destroying Objects inheritance in C# inheritance in C# Aggregations, Namespaces and Advance Scope Aggregations, Namespaces and Advance Scope Operators, Delegates and Events Operators, Delegates and Events Properties and Indexers Properties and Indexers
Fundamentals of Object-Fundamentals of Object-Oriented ProgrammingOriented Programming
What is OOPWhat is OOP Objects vs. Classes Objects vs. Classes Instantiation Instantiation Encapsulation Encapsulation Inheritance Inheritance Polymorphism Polymorphism
What is OOPWhat is OOP
Object-oriented programming (OOP) Object-oriented programming (OOP) is a programming language model is a programming language model organized around "objects" rather organized around "objects" rather than "actions" and data rather than than "actions" and data rather than logic. logic.
The first step in OOP is to identify all The first step in OOP is to identify all the objects you want to manipulate the objects you want to manipulate and how they relate to each other and how they relate to each other
Objects vs. ClassesObjects vs. Classes
Class HouseOfFunA blue print of the HouseOfFun house.
Object MyHouseAn Instance of HouseOfFun
Object YelloHouse[0] An Instance of HouseOfFun
Object MyHouseAn Instance of HouseOfFun
Object YelloHouse[1]An Instance of HouseOfFun
Objects vs. ClassesObjects vs. Classespublic class HouseOfFun{
public HouseOfFun(string city, int rooms, int buildYear)
{this.city = city;this.rooms = rooms;this.buildYear = buildYear;
}protected string city;protected int rooms;protected int buildYear;
public int calcHouseAge(){
// calculation just for this samplereturn (DateTime.Now.Year -
buildYear);}
}
InstantiationInstantiation
class mainClass{
static void Main( ){
HouseOfFun myHouse = new HouseOfFun("Tel Aviv",2,1963);
Console.WriteLine(myHouse.calcHouseAge());}
}
EncapsulationEncapsulation
The ability of an object to hide its The ability of an object to hide its internal data and methods, making internal data and methods, making only the intended parts of the object only the intended parts of the object programmatically accessible. programmatically accessible.
C# C# PublicPublic Private Private protected protected
InheritanceInheritance
Subclass that is defined can inherit the Subclass that is defined can inherit the definitions of one or more general definitions of one or more general classes.classes.
An object in a subclass need not carry An object in a subclass need not carry generic definition of data and methods generic definition of data and methods
speeds up program development;speeds up program development; ensures an inherent validity (what ensures an inherent validity (what
works and is consistent about the class works and is consistent about the class will also work for the subclass).will also work for the subclass).
PolymorphismPolymorphism
Polymorphism gives you the ability Polymorphism gives you the ability to group objects that have a common to group objects that have a common base class and treat them base class and treat them consistently.consistently.
Polymorphism allows you to extend Polymorphism allows you to extend or enhance your system without or enhance your system without modifying or breaking existing code.modifying or breaking existing code.
Encapsulation, Inheritance, Encapsulation, Inheritance, Polymorphism Polymorphism
Sample page 1/3: class with virtual Sample page 1/3: class with virtual methodmethodclass Teacher
{public Teacher(string firstName,string lastName,int
practiceYears,double payRate){
this.firstName = firstName;this.lastName = lastName;this.practiceYears = practiceYears;this.payRate = payRate;
}protected string firstName;protected string lastName;protected int practiceYears;protected double payRate;
public virtual double CalculatePayment(int hourseWorked){
// do somethingreturn 1,000,000.00; // bogus value
}}
Encapsulation, Inheritance, Encapsulation, Inheritance, Polymorphism - 2/3Polymorphism - 2/3
FullTimeTeacher is derived from FullTimeTeacher is derived from TeacherTeacherclass FullTimeTeacher:Teacher
{public FullTimeTeacher(string firstName,string lastName,int practiceYears,double payRate):base (firstName,lastName, practiceYears,payRate){}
public override double CalculatePayment(int hourseWorked) { //do something }}class PartTimeTeacher:Teacher{
public FullTimeTeacher(string firstName,string lastName,int practiceYears,double payRate):base (firstName,lastName, practiceYears,payRate){}
public override double CalculatePayment(int hourseWorked) { //do something }}
Encapsulation, Inheritance, Polymorphism 3/3Encapsulation, Inheritance, Polymorphism 3/3
- teachers group hold FullTimeTeacher & - teachers group hold FullTimeTeacher & PartTimeTeacherPartTimeTeacher
- CalculatePayment code stays the same - CalculatePayment code stays the same class PolymorphismSample{
protected Teacher[] teachers; protected void LoadTeachers(){
//in a real world situation we will use the database teachers = new Teacher[2];teachers[0] = new FullTimeTeacher("Marta",
"Kohen", 25, 2500.00);teachers[2] = new PartTimeTeacher("Bar",
"Shalom", 40, 50.00);} protected void CalculatePayment(){
foreach(Teacher tcr in teachers){
tcr.CalculatePayment(40);}
} }
Introducing Introducing Microsoft .NET Microsoft .NET
The .NET Framework The .NET Framework The Common Language Runtime The Common Language Runtime The .NET Framework Class Libraries The .NET Framework Class Libraries Microsoft Intermediate Language Microsoft Intermediate Language
and the Jitters and the Jitters Unified Type System Unified Type System Metadata and Reflection Metadata and Reflection
The .NET FrameworkThe .NET Framework
ASP.NET Windows Forms
Data and XML
Base Classes
Common Language Runtime
The Common Language The Common Language RuntimeRuntime
Common Type System
GC, Stack Walk, Code Manager
Class Loader & Memory Layout
Intermediate Languageto
Native Code Compilers
ExecutionSupport
Security
The .NET Framework Class The .NET Framework Class LibrariesLibraries
.Net Class Libraries provides language interoperability.
Sample:
The Class shown in this class Browser
System.Data.OleDb.OleDbConnection
can be used by all the many .Net languages
Microsoft Intermediate Microsoft Intermediate Language and the JittersLanguage and the Jitters
Unified Type SystemUnified Type System
Metadata and ReflectionMetadata and Reflection
Overview of C#Overview of C#
Structure of a c# program Structure of a c# program Basic Input/Output Operations Basic Input/Output Operations Recommended Practices Recommended Practices Compiling Running and Debugging Compiling Running and Debugging
Using Value-Type Using Value-Type variablesvariables
Common Type System Common Type System Naming Variables Naming Variables Using Built-in Data Types Using Built-in Data Types Compound Assignment Compound Assignment Increment and Decrement Increment and Decrement Creating User Defined Data Types Creating User Defined Data Types Converting Data Types Converting Data Types
Statements and Statements and ExceptionsExceptions
Selection Statements Selection Statements Iteration Statements Iteration Statements Jump Statements Jump Statements Handling Basic Exceptions Handling Basic Exceptions Raising Exceptions Raising Exceptions
Methods and ParametersMethods and Parameters
Methods Methods Parameters Parameters Overload Methods Overload Methods
Strings Arrays and Strings Arrays and CollectionsCollections
Strings Strings Creating Arrays Creating Arrays Using Arrays Using Arrays Collections Collections .NET Framework Arrays .NET Framework Arrays .Net Framework Collections .Net Framework Collections working with Strings, Enumerators working with Strings, Enumerators
and Collections and Collections
C# and Object Oriented C# and Object Oriented ProgrammingProgramming
Creating and using Classes Creating and using Classes
Using Reference-Type Using Reference-Type VariablesVariables
Reference-Type Variables Reference-Type Variables Common Reference Types Common Reference Types The Object Hierarchy The Object Hierarchy Namespaces in the .Net Framework Namespaces in the .Net Framework Data Conversions Data Conversions Type-Safe Casting Type-Safe Casting
Creating and Destroying Creating and Destroying ObjectsObjects
Constructors Constructors Initializing Data Initializing Data Objects and Memory Objects and Memory Destructors Destructors
inheritance in C# inheritance in C#
Deriving Classes Deriving Classes Implementing Methods Implementing Methods Sealed Classes Sealed Classes Interfaces Interfaces Abstract Classes Abstract Classes
Aggregations, Namespaces Aggregations, Namespaces and Advance Scopeand Advance Scope
Using internal classes, Methods and Using internal classes, Methods and Data Data
Using Aggregation Using Aggregation Using Namespaces Using Namespaces Using Modules and Assemblies Using Modules and Assemblies
Operators, Delegates and Operators, Delegates and EventsEvents
Operators Operators Operator Overloading Operator Overloading Delegates Delegates Events Events When to use Delegates, Events and When to use Delegates, Events and
Interfaces Interfaces
Properties and IndexersProperties and Indexers
properties properties Indexers Indexers
ReviewReview
C# Advance C# Advance
Attributes Attributes The SDK Tools The SDK Tools
AttributesAttributes
Overview of attributes Overview of attributes Defining Custom Attributes Defining Custom Attributes Retrieving Attributes Values Retrieving Attributes Values
The SDK ToolsThe SDK Tools
Configuration and Deployment Tools Configuration and Deployment Tools Debugging Tools Debugging Tools Security Tools and Utilities Security Tools and Utilities General Tools General Tools
ReviewReview