INF230 Basics in C# Programming

Slides:



Advertisements
Similar presentations
© by Pearson Education, Inc. All Rights Reserved.
Advertisements

Exploring Office Grauer and Barber 1 Creating More Powerful Applications: Introduction to VBA(Wk9)
Advanced Object-Oriented Programming Features
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# Programming: From Problem Analysis to Program Design1 10 Advanced Object-Oriented Programming Features C# Programming: From Problem Analysis to Program.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
Creating a Console Application with Visual Studio
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
A First Program Using C#
Visual Basic Chapter 1 Mr. Wangler.
Lecture Roger Sutton CO530 Automation Tools 5: Class Libraries and Assemblies 1.
Microsoft Visual Basic 2005: Reloaded Second Edition
An Object-Oriented Approach to Programming Logic and Design
Computing IV Visual C Introduction with OpenCV Example Xinwen Fu.
Using Visual Studio 2013 An Integrated Development Environment (IDE)
1 v1.6 08/02/2006 Overview of Eclipse Lectures 1.Overview 2.Installing and Running 3.Building and Running Java Classes 4.Refactoring 5.Debugging 6.Testing.
IE 411/511: Visual Programming for Industrial Applications
Lecture Set 1 Part C: Understanding Visual Studio and.NET – Applications, Solutions, Projects (no longer used – embedded in Lecture Set 2A)
CSCI-383 Object-Oriented Programming & Design Lecture 13.
1 INF160 IS Development Environments AUBG, COS dept Lecture 06 Title: Dev Env: Visual Studio (Extract from Syllabus) Reference:
Chapter 6 OOP: Creating Object-Oriented Programs Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
Lecture Set 2 Part A: Creating an Application with Visual Studio – Solutions, Projects, Files.
Using Microsoft Visual Studio 2005 Original by Suma Rao Revised by John G. McMahon ( 9/6/2008 )
C++ Programming Basic Learning Prepared By The Smartpath Information systems
C# Programming: From Problem Analysis to Program Design1 10 Advanced Object-Oriented Programming Features C# Programming: From Problem Analysis to Program.
Microsoft Visual Basic 2008 CHAPTER ELEVEN Multiple Classes and Inheritance.
1.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Lecture Set 2 Part A: Creating an Application with Visual Studio – Solutions, Projects, Files 8/10/ :35 PM.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
IS 350 Course Introduction. Slide 2 Objectives Identify the steps performed in the software development life cycle Describe selected tools used to design.
Building C# Applications
Dive Into® Visual Basic 2010 Express
Introduction to Object-oriented Programming
Visual Basic.NET Windows Programming
Chapter 2: The Visual Studio .NET Development Environment
Creating Your Own Classes
Visit for more Learning Resources
Working in the Forms Developer Environment
Dependency Analysis Use Cases
Chapter 1: An Introduction to Visual Basic 2015
Advanced Object-Oriented Programming Features
Chapter 2 – Introduction to the Visual Studio .NET IDE
Multiple Classes and Inheritance
OOP What is problem? Solution? OOP
Advanced Object-Oriented Programming Features
Reference: COS240 Syllabus
Dependency Analysis Use Cases
Advanced Object-Oriented Programming Features
CS360 Windows Programming
C# Programming: From Problem Analysis to Program Design
VISUAL BASIC.
Social Media And Global Computing Introduction to Visual Studio
Understanding the Visual IDE
CIS16 Application Development Programming with Visual Basic
Using JDeveloper.
Social Media And Global Computing Using DLLs with MVC
Lecture Set 11 Creating and Using Classes
Social Media And Global Computing Creating DLLs with Visual Studio
Chapter 3 – Introduction to C# Programming
Object-Oriented Programming: Classes and Objects
Tonga Institute of Higher Education
How to organize and document your classes
Java IDE Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
The Role of Command Line Compiler (csc.exe)
Presentation transcript:

INF230 Basics in C# Programming AUBG, COS dept Lecture 29 Title: DLL libraries, ILDASM (part 1) Reference: Doyle, chap 11

Chapter 11 Advanced Object-Oriented Programming Features C# Programming: From Problem Analysis to Program Design 4th Edition

Lecture Contents: OOP Features (reminder) Advanced OOP features. Abstraction , Encapsulation, Inheritance, Polymorphism, Generics Advanced OOP features. Component-Based Development Multi tier apps – Business, Presentation, Data layers, components Using libraries DLL to implement components

Object-Oriented Language Features Abstraction Generalizing, identifying essential features, hiding nonessential complexities Encapsulation Packaging data and behaviors into a single unit, hiding implementation details Inheritance Extending program units to enable reuse of code Polymorphism Providing multiple (different) implementations of same named behaviors C# Programming: From Problem Analysis to Program Design

Component-Based Development Figure 11-1 Component-based development C# Programming: From Problem Analysis to Program Design

Component-Based Development (continued) Component-based applications associated with multitier applications – (different layers) Business layer(s) – classes that perform processing Provide functionality for specific system; provide necessary processing Data access layer - classes for accessing data from text files and databases Presentation layer - User interface tier for user interaction Graphical User Interface such as Windows or Web C# Programming: From Problem Analysis to Program Design

Component-Based Development (continued) Components facilitates reuse-based approach Define and implement independent components into systems Components are implemented through classes Takes the form of objects or collection of objects Components can then be packaged with different components and used for other applications Classes can be created that extend functionality of original classes C# Programming: From Problem Analysis to Program Design

Component-Based Development (continued) SW products structure classification Logical structure Multi tier organization – UI layer, business layer, DB access layer Physical structure All components in sole package/module/file: NO SW reusability Components saved in a container prepared for reusability in many applications Most often container is organized as a library – static (.lib) or dynamic (.dll) C# Programming: From Problem Analysis to Program Design

DLL and ILDASM THE NEED of DLL as container of reusable code fragments (present lecture) The need of program tools to explore code fragments (next lecture)

Run Demo programs on DLL

Details on Compilation The C# compiler compiles source code (as a set of files with .cs as an extension) into an assembly. An assembly is the unit of packaging and deployment in .NET. An assembly can be either an application or a library. A normal console or Windows application has a Main() method and is an .exe file. A library is a .dll file and is equivalent to .exe without an entry point. Its purpose is to be called upon (referenced) by an application or by other libraries. C# Programming: From Problem Analysis to Program Design

Creating DLL

Dynamic Link Library (DLL) Several alternate options for creating components One option – compile source code into .dll file type Once you have DLL, any application that wants to use it just adds a reference to the DLL That referenced file with the .dll extension becomes part of the application’s private assembly First way: Can use the command line to create DLL C# Programming: From Problem Analysis to Program Design

A. Using command line to create DLL files To create DLL from MS VS cmd prompt. You get it: Start>All Programs>MS VSxx>VSTools>Developer Cmd prompt for VSxx At the cmd prompt you should type cmd like this: csc /target:library /out:Counter.dll Counter.cs You can specify more input files csc /target:library /out:Counter.dll Counter.cs P1.cs P2.cs Option /target:library makes compiler to generate .dll instead .exe Option /out may omit. Then output file is named after first listed source C# Programming: From Problem Analysis to Program Design

Dynamic Link Library (DLL) Using command line to create DLL files csc /target:exe build a console executable csc /target:winexe build Windows executable csc /target:library build a library csc /target:module build a module that can be added to another assembly C# Programming: From Problem Analysis to Program Design

B. Using VS to create DLL files Second way: more user friendly and attractive from within VS. You should select Class Library template for a project C# Programming: From Problem Analysis to Program Design

Building instead of Running Project The source code that you type includes one or more class definitions. These classes have no Main() method within them. To compile and create DLL, you select options under Build menu: Build > Build Solution Build > ReBuild Solution C# Programming: From Problem Analysis to Program Design

Client App to use the DLL Creating Client App to use the DLL

Creating a Client App to use DLL The created DLL can be reused with many different apps. You need to do two steps to use the DLL First: to add a reference to the components in your program Second: to include using directive with the appropriate namespace C# Programming: From Problem Analysis to Program Design

Sample Demo Projects INF230CreateLibrary INF230UsePrivateLibrary The project name identifies the library name, i.e. this project creates file INF230CreateLibrary.dll INF230UsePrivateLibrary The client project needs to include: using INF230CreateLibrary; // namespace directive To add a reference from within the project to the newly created user dll C# Programming: From Problem Analysis to Program Design

Sample Demo Projects DLLCreateClassLibrary DLLUseClassLibrary The project name identifies the library name, i.e. this project creates file DLLCreateClassLibrary.dll DLLUseClassLibrary The client project needs to include: using DLLCreateClassLibrary; // namespace directive To add a reference from within the project to the newly created user dll C# Programming: From Problem Analysis to Program Design

Build Instead of Run to Create DLL Create the parent class first in order to use IntelliSense (for sub classes) To illustrate creating stand-alone components, separate project created for Person and Student Because Visual Studio assigns the namespace name the same name as the project name (Person), you should change the namespace identifier If you don’t change it, when you start adding a reference to a created DLL, it can become confusing Changed to PersonNamespace for the example C# Programming: From Problem Analysis to Program Design

Build Instead of Run to Create DLL After typing class, do not run it – select BUILD, Build Solution Figure 11-7 Attempting to run a class library file Create new project for subclasses (Student) Again, select Class Library template from Start page Change namespace identifier (StudentNamespace) C# Programming: From Problem Analysis to Program Design

Build Instead of Run to Create DLL (continued) Add a new using statement to subclass In Student, add using PersonNamespace; To gain access to base class members in subclass, Add Reference in subclass to base class Use Solution Explorer window DLL is stored in Debug directory under the bin folder wherever you create the project C# Programming: From Problem Analysis to Program Design

Add Reference to Base Class One of the first things to do is Add a Reference to the Parent DLL Figure 11-8 Adding a reference to a DLL C# Programming: From Problem Analysis to Program Design

Add Reference to Base Class (continued) Use Browse button to locate DLL Figure 11-9 Add Reference dialog box C# Programming: From Problem Analysis to Program Design

Add Reference to Base Class (continued) Figure 11-10 Locating the Person.dll component C# Programming: From Problem Analysis to Program Design

Adding a New Using Statement In the subclass class, if you simply type the following, you receive an error message public class Student : Person Figure 11-11 Namespace reference error C# Programming: From Problem Analysis to Program Design

Adding a New Using Statement (continued) Notice fully qualified name To avoid error, could type: public class Student : PersonNamespace.Person Better option is to add a using directive using PersonNamespace; // Use whatever name you // typed for the namespace for Person After typing program statements, build the DLL from the Build option under the BUILD menu bar C# Programming: From Problem Analysis to Program Design

Creating a Client Application to Use the DLL DLL components can be reused with many different applications Once the component is in the library, any number of applications can reference it Instantiate objects of the referenced DLL Two steps Required Add a reference to the DLL components Include a using statement with the namespace name C# Programming: From Problem Analysis to Program Design

Creating a Client Application to Use the DLL (continued) Figure 11-12 DLLs referenced in the PresentationGUI class C# Programming: From Problem Analysis to Program Design

Practical session Creating DLL Creating a client app to use the DLL C# Programming: From Problem Analysis to Program Design

Classes as DLL contents Project ClassLibrary3 Contains class Counter definition Contains class Distance definition File ClassCountDistDefined.cs Project ClassLibrary3UsedBySB Contains references to Counter class Contains references to Distance class File ClassCountDistUsed.cs C# Programming: From Problem Analysis to Program Design

Classes as DLL contents Compile and run a pair of projects based on DLL ClassLibrary3 C# Programming: From Problem Analysis to Program Design

Structures as DLL contents Project ClassLibrary4 Contains struct Book definition File StructBookDefined.cs Project ClassLibrary4UsedBySB Contains references to Book struct File StructBookUsed.cs C# Programming: From Problem Analysis to Program Design

Structures as DLL contents Compile and run a pair of projects based on DLL ClassLibrary4 C# Programming: From Problem Analysis to Program Design

Interfaces as DLL contents Project ClassLiIbrary5 Contains interface ITraveler definition File ITravelerDefined.cs Project ClassLibrary5UsedBySB Contains references to Itraveler interface File ITravelerUsed.cs C# Programming: From Problem Analysis to Program Design

Interfaces as DLL contents Compile and run a pair of projects based on DLL ClassLibrary5 C# Programming: From Problem Analysis to Program Design

Thank You For Your Attention!

Using ILDASM to View the Assembly (ILDASM): Intermediate Language Disassembler tool Assembly shows the signatures of all methods, data fields, and properties One option – display the source code as a comment in the assembly Can be run from the command line or from within the Visual Studio IDE C# Programming: From Problem Analysis to Program Design

Using ILDASM to View the Assembly (continued) In order to use ILDASM in Visual Student, must be added as an external tool in Visual Studio (TOOLS, External Tools…) DLL files cannot be modified or viewed as source code Can use ILDASM to view DLL assemblies C# Programming: From Problem Analysis to Program Design

ILDASM to View the Assembly .ctors are constructors IL code for the method Data fields Properties converted to methods Figure 11-14 Student.dll assembly from ILDASM C# Programming: From Problem Analysis to Program Design

Thank You For Your Attention!