IEG 3080 Tutorial 1 - PowerPoint PPT Presentation

1 / 24
About This Presentation
Title:

IEG 3080 Tutorial 1

Description:

MS platform only, Mono project provides alternative to run .Net on Linux platform. ... A reference is added to the project ... the maintenance of large project ... – PowerPoint PPT presentation

Number of Views:51
Avg rating:3.0/5.0
Slides: 25
Provided by: raymo89
Category:
Tags: ieg | ms | project | tutorial

less

Transcript and Presenter's Notes

Title: IEG 3080 Tutorial 1


1
IEG 3080 Tutorial 1
  • Raymond Lam

2
Outline
  • Overview of .Net
  • Assembly
  • Object Oriented Programming
  • Assignment 1 2
  • Debug with VS .Net 2005

3
Overview of .Net
Figure extracted from M. Chang, Lecture Note 1,
p.45
4
Overview of .Net
  • Support various programming language
  • With CLR (Common Language Runtime), all languages
    are compiled into the same intermediate language
    (MSIL) code, similar to JVM in java
  • Support cross-language inheritance(e.g. a VB
    class derived from a C class)

5
Overview of .Net
  • Disadvantage
  • Slower response due to loading time for
    converting byte code (Slower than C)
  • Non-multiplatform
  • MS platform only,
  • Mono project provides alternative to run .Net on
    Linux platform. http//www.mono-project.com/Main_P
    age

6
Assembly
  • What is an assembly?
  • A library component
  • Basic unit of a binary file in .Net
  • Byte code of single or multiple source files
  • With the assembly, programmers can simply reuse
    the implementation without knowing the source
    code
  • E.g. abc.dll, xyz.dll
  • Notes Not all dll are generated by .Net!!!

7
Assembly
  • Make a sharable component
  • By command
  • Using Visual Studio 2005 Command Prompt, not the
    Microsoft Command Prompt (unless you have set the
    PATH)
  • E.g. csc /tlibrary HelloMsg.cs
  • Output HelloMsg.dll

8
Assembly
  • By Visual Studio .Net 2005
  • Create a Class Library, but not Application

9
Assembly
  • To use a sharable component
  • By command
  • E.g. csc /tlibrary HelloMsg.cs
  • csc /rHelloMsg.dll HelloApp.cs
  • By Visual Studio .Net 2005

10
Assembly
11
Assembly
  • A reference is added to the project
  • Simply build HelloApp project only, and the
    output is located at project path\bin\Debug
    or project path\bin\Release
  • There should be 2 major outputs, a Hello.exe and
    HelloMsg.dll
  • The exe and the dll must be in the same folder
    (unless you have registered the dll in GAC)

12
Assembly
  • Strong-name Assembly
  • Distribute the library component authenticity and
    integrity check
  • By public and private key algorithm
  • (GAC) Global Assembly Cache
  • Centralize the shared library (Strong-name
    assembly only)
  • Located at system root/assembly
  • Dont try to uninstall the assembly which you do
    not know what it is, otherwise your computer may
    be fail to boot up next time

13
Assembly
  • Example (refer to Lecture Notes P.56)
  • Generate the key filesn k myKey.snk
  • Add code to source file to specify version and
    key info
  • if STRONG
  • assembly System.Reflection.AssemblyVersion(1.0.
    0.0)
  • assembly System.Reflection.AssemblyKeyFile(myKe
    y.snk)
  • endif
  • Compile
  • csc /defineSTRONG /tlibrary /outHelloMsg.dll
    HelloMsg.cs
  • Add to GAC
  • gacutil.exe /if HelloMsg.dll

14
Object Oriented Programming
  • Encapsulation
  • Inheritance
  • Polymorphism
  • Delegation

15
OOP - Encapsulation
  • Hide the complexity from the outside world
  • Only expose the interface
  • Everything acts as a black box, you can only see
    the input and output
  • Reason
  • The less detail of the implementation you know,
    the easier it is when you change your
    implementation
  • Other implementations will not be affected if the
    interface has not been changed

16
OOP - Encapsulation
  • Easy for the maintenance of large project
  • Once the interface are compromised, it is no need
    to know what the implementation is
  • Easy for further development, e.g. extension,
    version upgrade
  • Import to develop large solution, e.g. ERP
    (Enterprise Resource Program), DMS (Document
    Management System), etc

17
OOP - Encapsulation
  • Visibility
  • public (PacalCasing)
  • Accessible from anywhere
  • private (camelCasing)
  • Only accessible in the same class
  • protected
  • Only accessible in the same class and its
    subclass
  • internal
  • Only accessible within assembly (name space)
  • protected internal
  • Only accessible within assembly or the subclass

18
OOP - Inheritance
  • Object with similar properties can belong to a
    more general object
  • Better Structure
  • E.g.

19
OOP - Inheritance
  • Account Bank inherit Object
  • Trivial
  • Account is inherited by Saving Account Current
    Account
  • Because saving and current account have similar
    properties
  • Deposit and Withdraw

20
OOP Inheritance Example
Child class
Parent class
Internal variable
  • Account
  • Saving Account
  • public class Account
  • protected int _balance 0
  • public virtual string GetName()
  • return Account
  • public int GetBalance ()
  • return _balance
  • public virtual void Deposit (int amount)
  • public class Saving Account
  • public override string GetName() return
    Saving
  • public override void Deposit (int amount)

camelCasing
Override method
PascalCasing
Implementation
21
Polymorphism
  • One interface, multiple implementation
  • E.g. Account accounts new Account2account
    s0 new SavingAccount()accounts1 new
    CurrentAccount()
  • accounts0.Deposit(100)accounts1.Deposit(30
    0)foreach (Account account in accounts)
    Console.WriteLine(account.GetName()
    account.GetBalance())
  • Output Saving 100 Current 300

22
Assignment
  • Assignment 1
  • GAC practice
  • Assignment 2
  • OOP practice
  • Try to think in OOP way
  • Prevent using C coding style
  • Do earilier

23
Debug with VS.Net 2005
Set break point
24
Debug with VS.Net 2005
You can even drag the pointer to any place in the
same method
  • Useful Reference
  • MSDN - http//msdn2.microsoft.com/en-us/default.as
    px
Write a Comment
User Comments (0)
About PowerShow.com