Introduction to .NET Florin Olariu

Slides:



Advertisements
Similar presentations
OOP Abstraction Classes Class Members: Properties & Methods Instance (object) Encapsulation Interfaces Inheritance Composition Polymorphism Using Inheritance.
Advertisements

CS 211 Inheritance AAA.
Inheritance Inheritance Reserved word protected Reserved word super
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 8.1 – 8.5.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Abstraction: Polymorphism, pt. 1 Abstracting Objects.
Inheritance. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 Inheritance Inheritance is a fundamental object-oriented design technique used to.
C# Classes and Inheritance CNS 3260 C#.NET Software Development.
Object Orientation An Object oriented approach views systems and programs as a collection of interacting objects. An object is a thing in a computer system.
Programming Pillars Introduction to Object- Oriented Programming.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
ILM Proprietary and Confidential -
Inheritance. Inheritance is a fundamental object-oriented design technique used to create and organize reusable classes Chapter 8 focuses on: deriving.
Introduction to Object-Oriented Programming Lesson 2.
Coming up: Inheritance
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
Presented by Ted Higgins, SQL Server DBA An Introduction to Object – Oriented Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Outline Creating Subclasses Overriding Methods Class Hierarchies Inheritance.
2 Arrays Array is a data structure that represents a collection of the same type of data. A "fixed length list".
Data Structures Lecture 4: Classes in C++ Azhar Maqsood NUST Institute of Information Technology (NIIT)
CH 1-4 : INTRODUCTION ACKNOWLEDGEMENT: THE SLIDES ARE PREPARED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND.
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Introduction to.NET Florin Olariu “Alexandru Ioan Cuza”, University of Iai Department of Computer Science.
Inheritance and Polymorphism
Principles of programming languages 10: Object oriented languages
Lecture 10 Collections Richard Gesick.
Modern Programming Tools And Techniques-I
Inheritance Chapter 7 Inheritance Basics Programming with Inheritance
Object-Oriented Programming Concepts
CIS 200 Test 01 Review.
Ch 10- Advanced Object-Oriented Programming Features
2.7 Inheritance Types of inheritance
Software Engineering Fall 2005
Inheritance & Polymorphism
About the Presentations
Advanced Programming in Java
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
PRINCIPALES OF OBJECT ORIENTED PROGRAMMING
C# Programming Arrays in C# Declaring Arrays of Different Types Initializing Array Accessing Array Elements Creating User Interfaces Using Windows Standards.
Object Oriented Concepts
Introduction to .NET Florin Olariu & Andrei Arusoaie
CS360 Windows Programming
ATS Application Programming: Java Programming
Functional Programming with Java
MIS Professor Sandvig MIS 324 Professor Sandvig
Object Oriented Analysis and Design
.NET and .NET Core 5.2 Type Operations Pan Wuming 2016.
OOP’S Concepts in C#.Net
.NET and .NET Core 9. Towards Higher Order Pan Wuming 2017.
Typescript Programming Languages
Inheritance Basics Programming with Inheritance
Arrays.
Object-Oriented Programming
Polymorphism Polymorphism
Array-Based Implementations
Computer Programming with JAVA
9: POLYMORPHISM Programming Technique II (SCSJ1023) Jumail Bin Taliba
Java Programming Course
Topics discussed in this section:
Overriding Methods & Class Hierarchies
MIS Professor Sandvig MIS 324 Professor Sandvig
Introduction to Data Structure
Fundaments of Game Design
By Rajanikanth B OOP Concepts By Rajanikanth B
CIS 199 Final Review.
Introduction to .NET Florin Olariu
Fundaments of Game Design
Review of Previous Lesson
Object Oriented Design & Analysis
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
Presentation transcript:

Introduction to .NET Florin Olariu “Alexandru Ioan Cuza”, University of Iași Department of Computer Science

Agenda OOP in .NET Core Arrays Generic list What’s Next Demo Generic list What’s Next Interview questions

OOP in .NET Core Inheritance Inheritance Classes may derive from exiting classes. Existing classes are called : parent class. => and it is a generalization of the exiting class. Inheritance creates an “is –a ” relationship Example: Employee<=Manager, Architect, Technical Lead, Developer

OOP in .NET Core – inheritance Derived class indicates base class with colon. Notes: classes can contain properties and fields (built-in like int, string or custom like other classes or struct’s) Fields are used to support private methods Properties are used to expose functionality to other classes

OOP in .NET Core - inheritance Identify : properties, methods/behavior

OOP in .NET Core - polymorphism The possibility of taking many forms. Method overriding -> modify a method in the derived class : C# in order to be able to use method overriding we need to know: virtual  override. Virtual exists in base class, override in derived class.

OOP in .NET Core - polymorphism

OOP in .NET Core - polymorphism Another important aspect for polymorphism is “method overloading”. Means: we can have in the same class methods with the same name but different number of parameters.

OOP in .NET Core - encapsulation Encapsulation : a class should have a single responsibility. => don’t forget here, there is another set of principles : SOLID. Within the class we should have private functionality, that should not be exposed and only a : few well-defined methods that are public. Question: Why the method should be public?

OOP in .NET Core Inheritance Polymorphism Encapsulation There are 3 pillars in OOP. => Inheritance, polymorphism and encapsulation.

OOP in .NET Core "In the one and only true way. The object-oriented version of 'Spaghetti code' is, of course, …."

OOP in .NET Core "In the one and only true way. The object-oriented version of 'Spaghetti code' is, of course, 'Lasagna code'." - Roberto Waltman.

Arrays

Arrays Definition Declaring and populating an array Samples Declaring and populating an array Using collection initializers Retrieving an element from an array Iterating an array Using array methods Best practices Demo

Arrays Definition

Arrays Definition Is a fixed-size list of elements that can be accessed using a positional index number

Arrays Red “Salt” 2.21 White “Pepper” 3.43 Definition “Onion” 5.01 Is a fixed-size list of elements that can be accessed using a positional index number Sample: Red White Green Blue “Salt” 2.21 “Pepper” 3.43 “Onion” 5.01 “Garlic” 3.20 Notes: 1. In arrays index is “0-based”. 2. Arrays are fixed size.(we will define the size of an array when this is initialized – once is initialized the size cannot be adjusted)

Arrays Definition 1 2 3 Red White Green Blue 1 2 3 “Salt” 2.21 Is a fixed-size list of elements that can be accessed using a positional index number Sample: 1 2 3 Red White Green Blue 1 2 3 “Salt” 2.21 “Pepper” 3.43 “Onion” 5.01 “Garlic” 3.20 Notes: In arrays index is “0-based”.

Arrays Definition Samples Declaring and populating an array

Arrays Red White Definition Green Declaring and populating an array Samples Declaring and populating an array Declaring an array: string[] colors; Red White Green Blue

Arrays Red White Green Blue Definition Samples Declaring and populating an array Declaring an array: Initializing an array: string[] colors; string[] colors; colors = new string[4]; string[] colors = new string[4]; var colors = new string[4]; Red White Green Blue An array is a reference type. In this case we should use: “new” keyword for initialization.

Arrays Definition Declaring and populating an array Samples

Arrays Definition Declaring and populating an array Samples var colors = new string[4]; colors[0] = “Red”; colors[1] = “White”; colors[2] = “Green”; colors[3] = “Blue”; An array is a reference type. In this case we should use: “new” keyword for initialization.

Arrays Best practices Do Avoid Use arrays when the size is known at the design time Do not use arrays when the data comes from a database call For an array name use ‘pluralization’ => Colors

Arrays Demo

Generic List

Generic List Definition Arrays vs Generic List Declaring and populating Generic Lists Using initializers Retrieving elements from Generic lists Iterating through a Generic List Demo

Generic List Definition It is a strongly typed list of elements that is accessed using a positional index number.

Generic List Arrays vs Generic List

Generic List Arrays vs Generic List Arrays Generic List

Generic List Arrays vs Generic List Arrays Generic List Strongly typed

Generic List Arrays vs Generic List Arrays Generic List Strongly typed Fixed length Expandable

Generic List Arrays vs Generic List Arrays Generic List Strongly typed Fixed length Expandable The is no ability to add/remove elements Can add, insert or remove elements

Generic List Arrays vs Generic List Arrays Generic List Strongly typed Fixed length Expandable The is no ability to add/remove elements Can add, insert or remove elements Multi-dimensional One-dimensional

Generic List Declaring and populating Generic Lists

Generic List Declaring and populating Generic Lists

Generic List Declaring and populating Generic Lists This is using Collection initializer.

Generic List Frequently asked questions When is appropriate to use a generic list?

Generic List Frequently asked questions When is appropriate to use a generic list? Any time the application needs to manage a list of things What are the key differences between an array and a generic list?

Generic List Frequently asked questions When is appropriate to use a generic list? Any time the application needs to manage a list of things What are the key differences between an array and a generic list? An array is fixed length and can have multiple dimensions A generic list can have any length and provides methods to add, insert or remove elements Execution time

Generic List Frequently asked questions When is appropriate to use a generic list? Any time the application needs to manage a list of things What are the key difference between an array and a generic list? An array is fixed length and can have multiple dimensions A generic list can have any length and provides methods to add,insert or remove elements Execution time For this samples I used: List<int> list = new List<int>(6000000); The second number is a checksum to verify they all did the same work. static class Program { static void Main() Random rand = new Random(12345); for (int i = 0; i < 6000000; i++) list.Add(rand.Next(5000)); } int[] arr = list.ToArray(); int chk = 0; Stopwatch watch = Stopwatch.StartNew(); for (int rpt = 0; rpt < 100; rpt++) int len = list.Count; for (int i = 0; i < len; i++) chk += list[i]; watch.Stop(); Console.WriteLine("List/for: {0}ms ({1})", watch.ElapsedMilliseconds, chk); chk = 0; watch = Stopwatch.StartNew(); for (int i = 0; i < arr.Length; i++) chk += arr[i]; Console.WriteLine("Array/for: {0}ms ({1})", watch.ElapsedMilliseconds, chk); foreach (int i in list) chk += i; Console.WriteLine("List/foreach: {0}ms ({1})", watch.ElapsedMilliseconds, chk); foreach (int i in arr) Console.WriteLine("Array/foreach: {0}ms ({1})", watch.ElapsedMilliseconds, chk); Console.ReadLine(); List/for: 1971ms (589725196) Array/for: 1864ms (589725196) List/foreach: 3054ms (589725196) Array/foreach: 1860ms (589725196)

Generic List Demo

What’s next … Generic dictionaries Generic collection interfaces LINQ

Interview questions Abstract classes vs Interfaces Boxing/Unboxing Immutable string

One more thing…  "Walking on water and developing software from a specification are easy…"

One more thing…   "Walking on water and developing software from a specification are easy if both are frozen." - Edward V Berard

Questions Do you have any other questions?

Thanks! See you next time! 