SlideShare a Scribd company logo
1 of 42
Object Oriented Software
Development
2. C# object oriented programming basics
What is object oriented
programming?
 A programming approach which uses objects
 An object is a software component which has
properties and behaviour
 When a program runs objects are created and
work together to perform the program’s tasks
 Most modern programming languages support
object orientation
 C#, Java, VB.NET, C++, PHP, etc.
Object Oriented Software Development 2. C# object oriented programming basics
2
Where should we use it?
 Object-orientation offers some key benefits:
 Code re-use – DRY principle
 Ability to model real-world environments
 Understandability
 Many kinds of software application can
benefit from object oriented approach
 GUI applications, web applications, games,
etc.
Object Oriented Software Development 2. C# object oriented programming basics
3
Objects
 An entity, or thing, is represented as an
object in the program
 e.g. an object representing an Employee in a
company
 Objects have attributes to represent state of
object, e.g. name, location of an Employee
 Objects have methods to define the actions,
or behaviour, which object can perform, e.g.
an Employee could record that he or she
worked some overtime hours
Object Oriented Software Development 2. C# object oriented programming basics
4
Responsibilities and collaboration
 Objects have responsibilities
 This allows objects to interact, or
collaborate, with each other
 Program consists of objects which interact,
just as real world entities interact
 For example, in a real-world company each
person has a job to do (responsibilities), and
people collaborate to achieve the company’s
aims
Object Oriented Software Development 2. C# object oriented programming basics
5
Encapsulation
 Objects are able to collaborate through
behaviour and attributes which are public
 Objects can also have behaviour and
attributes which are private
 These are for the object itself to use in
performing its responsibilities
 Public behaviour may modify private
attributes or use private behaviour
 Collaborating objects do not need to know
about these
Object Oriented Software Development 2. C# object oriented programming basics
6
Classes
 May have more than one object of the same
kind that have common characteristics
 Class is a template for creating objects of the
same kind
 A bit like a job description for a real-world job
 Employee class can be used to create
many Employee objects
 When we write the code we are actually
writing the class definitions
Object Oriented Software Development 2. C# object oriented programming basics
7
Classes and objects
 An object is a specific instance of a class
 Class defines the attributes and methods
which are common to all instances of class
 Each object can have its own specific values
for these attributes
 Each Employee object will have a Name, but
the value is different in each object
 Objects are created from the class as the
program runs
Object Oriented Software Development 2. C# object oriented programming basics
8
What’s in a class
 A class is written as a named a block of code
 Contains declarations of variables to
represent the attributes
 Contains blocks of code, nested within the
class, to define the methods
 Each method contains a sequence of steps
which carry out the action which that method
defines
 Usually contains one or more constructors
Object Oriented Software Development 2. C# object oriented programming basics
9
C# class example code
 OOBasicsDemo project
 Employee.cs
Object Oriented Software Development 2. C# object oriented programming basics
10
Class diagrams
Object Oriented Software Development 2. C# object oriented programming basics
11
class name
attributes
methods
private – cannot be
accessed by other
objects
public – can be
accessed by other
objects
Object diagrams
Object Oriented Software Development 2. C# object oriented programming basics
12
name = Michael
username = michael
currentLocation = loc
phoneNumber = 1234
emp1 : Employee
name = Susan
username = susan
currentLocation = loc
phoneNumber = 4321
emp2 : Employee
each object here is an instance
of the Employee class with its
own values for the attributes
Variables
 A variable is a name given to a piece of
information in a program
 Allows us write code which refers to and uses
that information
 Actual value will depend on what has
happened as the program runs
 May be different each time the program runs
and may change as it runs
Object Oriented Software Development 2. C# object oriented programming basics
13
Declaring variables
 In C# a variable needs to be declared before
it can be used
 Declaring a variable means specifying that a
particular piece of information may exist by
giving it a name and stating the type
int myValue
Declares a variable of type int with name “myValue”
Object Oriented Software Development 2. C# object oriented programming basics
14
Giving values to variables
 Can assign a value to a variable, e.g.
myValue = 3
myValue = x where x is another int variable
myValue = 3x
 Can assign at the same time as declaring,
e.g
int myValue = 3
Object Oriented Software Development 2. C# object oriented programming basics
15
Object references
 In an OO program, a variable can be an
object reference
 A name given to an object
 Allows us write code which refers to and uses
that object
 Need to declare variable:
Employee emp
 Need to create an object and assign it to this
variable
Object Oriented Software Development 2. C# object oriented programming basics
16
Instance variables
 Attributes of an object are also known as
instance variables or fields
 prefer these as attribute has another meaning in C#
 Each instance variable represents a piece of
information of a specific type, which can be:
 a C# built-in type, e.g. string, int
 any .NET Framework type, e.g. DateTime (we will
look at .NET types in more detail later)
 any class in your application, e.g. Location (a class
which would represent a work location)
Object Oriented Software Development 2. C# object oriented programming basics
17
C# creating objects example code
 OOBasicsDemo project
 Employee.cs
 Program.cs
Object Oriented Software Development 2. C# object oriented programming basics
18
Creating objects example
 Test program creates some objects and
make them do something
 Program.cs
 Main method – entry point to a C# application
 Creates object using new keyword
 emp1, emp2 are object references each of
which “points” to an object of type Employee
Object Oriented Software Development 2. C# object oriented programming basics
19
null references
 A reference can be null
 The reference is declared but does not
actually point to an object
Object Oriented Software Development 2. C# object oriented programming basics
20
reference declared, not assigned to object - null
reference assigned to object
reference no longer assigned to object - null
Constructors
 Constructor is executed when object is
created to initialise object
 Constructor is similar to a method, but must
have same name as the class
 Employee must have constructor with list of
parameters which match information supplied
Object Oriented Software Development 2. C# object oriented programming basics
21
Constructors
 Class can have more than one constructor,
each with different parameter list
 Employee has two constructors – one takes
no parameters (default constructor)
Object Oriented Software Development 2. C# object oriented programming basics
22
C# messages example code
 OOBasicsDemo project
 Employee.cs
 TimeSheet.cs
 Program.cs
Object Oriented Software Development 2. C# object oriented programming basics
23
Messages
 Collaborating objects interact with each other
by sending messages
 Message is simply the name of a method to
be called on the receiving object
 Information may be passed to receiving
object as method parameter(s)
 Reply may be passed back as method return
value
Object Oriented Software Development 2. C# object oriented programming basics
24
Types of message
 Messages sent to an object may :
 Request information from that object
 Method will return a value
 Parameter(s) may provide further detail as to what
information to return
 Give an instruction to that object
 Method will (usually) not return a value
 Parameter(s) may provide further detail about
instruction
Object Oriented Software Development 2. C# object oriented programming basics
25
Sending messages to objects
 Send message by calling method
 In example code, method of Employee sends
message to a TimeSheet object to ask it to
add an entry
 Calls AddEntry method
 Employee does not need to know how
TimeSheet does this
 Note that test program sends message to
Employee object to start this off
Object Oriented Software Development 2. C# object oriented programming basics
26
Collaboration through messages
 In this example the Employee object and
TimeSheet object collaborate do perform the
task of recording the information about hours
worked
 Employee object has knowledge of hours
worked and responsibility for providing this
information to the TimeSheet object
 TimeSheet object has responsibility for
actually storing the information
Object Oriented Software Development 2. C# object oriented programming basics
27
Sequence diagram
Object Oriented Software Development 2. C# object oriented programming basics
28
Program emp1 ts
RecordOvertime()
AddEntry()
object
message
time
This diagram shows that Program calls RecordOvertime on
Employee object emp1, which as a result calls AddEntry on
TimeSheet object ts – look at code to see how this works
Method signatures
 Specify method name, return type and
parameter types, e.g.:
 RecordOvertime
 Needs number of hours as a parameter
 Needs TimeSheet object as a parameter
 returns no value (return type is void)
 Email
 Returns a string containing the email address
 Doesn’t need to pass any parameters
Object Oriented Software Development 2. C# object oriented programming basics
29
Class diagram with more detail
Object Oriented Software Development 2. C# object oriented programming basics
30
attribute types
parameters
return type
Methods and algorithms
 A method contains code which defines the
steps required to perform an action
 Sometimes this can be very simple:
 AddEntry method simply writes to console
 RecordOvertime method just sends a message to
another object
 Sometimes the action is more complicated,
and requires many steps to define an
algorithm
Object Oriented Software Development 2. C# object oriented programming basics
31
Methods and algorithms
 Algorithm is a step-by-step procedure to
solve a problem
 Steps are defined as program statements
 May involve combination of any of the
following:
 Calculations
 Decisions: if-else statements
 Repeated actions: for, while loops
 Calls to other methods
Object Oriented Software Development 2. C# object oriented programming basics
32
Relationships
 Need to define relationships to allow objects
to interact
 Can show relationships in class and object
diagrams
 Need to implement these in code
 Learn code patterns for implementing various
relationship types
Object Oriented Software Development 2. C# object oriented programming basics
33
“has-a” relationship
 One object contains one or more other
objects
 Department has Employees, Employee has-a
Location
 aggregation – shared ownership
 composition – exclusive ownership
 association – no ownership
 Usually implemented as an instance variable
in one class
 Employee has an attribute of type Location
Object Oriented Software Development 2. C# object oriented programming basics
34
“uses-a” relationship
 One object has some kind of association
with another
 Employee uses-a TimeSheet
 Association is temporary, not implemented by
instance variable
 Can be implemented through a method
parameter
 Employee’s RecordOvertime method has a
parameter of type TimeSheet
Object Oriented Software Development 2. C# object oriented programming basics
35
“is-a” relationship
 Inheritance relationship
 We will come back to this later...
Object Oriented Software Development 2. C# object oriented programming basics
36
C# relationships example code
 OOBasicsDemo project
 Employee.cs
 Location.cs
 TimeSheet.cs
 Department.cs
Object Oriented Software Development 2. C# object oriented programming basics
37
Relationships in class diagram
Object Oriented Software Development 2. C# object oriented programming basics
38
aggregation association (has-a)
association (uses-a)
Note that we are not showing the
currentLocation attribute of type
Location in the Employee class box
now as it is implied by the relationship
Relationships in object diagram
Object Oriented Software Development 2. C# object oriented programming basics
39
name : string = Michael
username : string = michael
phoneNumber : string = 1234
emp1 : Employee
name : string = Susan
username : string = susan
phoneNumber : string = 4321
emp2 : Employee
loc : Location
here there are two Employee
objects associated with the same
Location object
“snapshot” of objects which
exist at a point in time while
the program runs
Key OO concepts
 Object
 Class
 Message
 Relationship
Object Oriented Software Development 2. C# object oriented programming basics
40
What’s next?
 Next we will look in more detail at the syntax
of C# and how to write C# classes
Object Oriented Software Development 2. C# object oriented programming basics
41
Concepts
 Object
 Class
 Message
 Reusability
 Encapsulation
 Information hiding
Object Oriented Software Development 2. C# object oriented programming basics
42

More Related Content

Similar to Object Oriented Software Development, using c# programming language

Object Oriented PHP - PART-1
Object Oriented PHP - PART-1Object Oriented PHP - PART-1
Object Oriented PHP - PART-1Jalpesh Vasa
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorialsakreyi
 
C# Summer course - Lecture 1
C# Summer course - Lecture 1C# Summer course - Lecture 1
C# Summer course - Lecture 1mohamedsamyali
 
Sofwear deasign and need of design pattern
Sofwear deasign and need of design patternSofwear deasign and need of design pattern
Sofwear deasign and need of design patternchetankane
 
Intro to C++ - Class 2 - Objects & Classes
Intro to C++ - Class 2 - Objects & ClassesIntro to C++ - Class 2 - Objects & Classes
Intro to C++ - Class 2 - Objects & ClassesBlue Elephant Consulting
 
Intro To C++ - Class 2 - An Introduction To C++
Intro To C++ - Class 2 - An Introduction To C++Intro To C++ - Class 2 - An Introduction To C++
Intro To C++ - Class 2 - An Introduction To C++Blue Elephant Consulting
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)Jay Patel
 
Bca5020 visual programming
Bca5020  visual programmingBca5020  visual programming
Bca5020 visual programmingsmumbahelp
 
OOP lesson1 and Variables.pdf
OOP lesson1 and Variables.pdfOOP lesson1 and Variables.pdf
OOP lesson1 and Variables.pdfHouseMusica
 
Object Oriented Programming Lecture Notes
Object Oriented Programming Lecture NotesObject Oriented Programming Lecture Notes
Object Oriented Programming Lecture NotesFellowBuddy.com
 
Oop c sharp_part_1
Oop c sharp_part_1Oop c sharp_part_1
Oop c sharp_part_1shivaksn
 
WP7 HUB_Introducción a Silverlight
WP7 HUB_Introducción a SilverlightWP7 HUB_Introducción a Silverlight
WP7 HUB_Introducción a SilverlightMICTT Palma
 

Similar to Object Oriented Software Development, using c# programming language (20)

Chapter1
Chapter1Chapter1
Chapter1
 
Object Oriented PHP - PART-1
Object Oriented PHP - PART-1Object Oriented PHP - PART-1
Object Oriented PHP - PART-1
 
02 objective-c session 2
02  objective-c session 202  objective-c session 2
02 objective-c session 2
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
Introduction to Objective - C
Introduction to Objective - CIntroduction to Objective - C
Introduction to Objective - C
 
C# Summer course - Lecture 1
C# Summer course - Lecture 1C# Summer course - Lecture 1
C# Summer course - Lecture 1
 
C++ & VISUAL C++
C++ & VISUAL C++ C++ & VISUAL C++
C++ & VISUAL C++
 
Sofwear deasign and need of design pattern
Sofwear deasign and need of design patternSofwear deasign and need of design pattern
Sofwear deasign and need of design pattern
 
Intro to C++ - Class 2 - Objects & Classes
Intro to C++ - Class 2 - Objects & ClassesIntro to C++ - Class 2 - Objects & Classes
Intro to C++ - Class 2 - Objects & Classes
 
Intro To C++ - Class 2 - An Introduction To C++
Intro To C++ - Class 2 - An Introduction To C++Intro To C++ - Class 2 - An Introduction To C++
Intro To C++ - Class 2 - An Introduction To C++
 
OOP Programs
OOP ProgramsOOP Programs
OOP Programs
 
C++
C++C++
C++
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
 
Bca5020 visual programming
Bca5020  visual programmingBca5020  visual programming
Bca5020 visual programming
 
csharp.docx
csharp.docxcsharp.docx
csharp.docx
 
OOP lesson1 and Variables.pdf
OOP lesson1 and Variables.pdfOOP lesson1 and Variables.pdf
OOP lesson1 and Variables.pdf
 
Object Oriented Programming Lecture Notes
Object Oriented Programming Lecture NotesObject Oriented Programming Lecture Notes
Object Oriented Programming Lecture Notes
 
Oop c sharp_part_1
Oop c sharp_part_1Oop c sharp_part_1
Oop c sharp_part_1
 
Ch01
Ch01Ch01
Ch01
 
WP7 HUB_Introducción a Silverlight
WP7 HUB_Introducción a SilverlightWP7 HUB_Introducción a Silverlight
WP7 HUB_Introducción a Silverlight
 

Recently uploaded

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 

Recently uploaded (20)

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 

Object Oriented Software Development, using c# programming language

  • 1. Object Oriented Software Development 2. C# object oriented programming basics
  • 2. What is object oriented programming?  A programming approach which uses objects  An object is a software component which has properties and behaviour  When a program runs objects are created and work together to perform the program’s tasks  Most modern programming languages support object orientation  C#, Java, VB.NET, C++, PHP, etc. Object Oriented Software Development 2. C# object oriented programming basics 2
  • 3. Where should we use it?  Object-orientation offers some key benefits:  Code re-use – DRY principle  Ability to model real-world environments  Understandability  Many kinds of software application can benefit from object oriented approach  GUI applications, web applications, games, etc. Object Oriented Software Development 2. C# object oriented programming basics 3
  • 4. Objects  An entity, or thing, is represented as an object in the program  e.g. an object representing an Employee in a company  Objects have attributes to represent state of object, e.g. name, location of an Employee  Objects have methods to define the actions, or behaviour, which object can perform, e.g. an Employee could record that he or she worked some overtime hours Object Oriented Software Development 2. C# object oriented programming basics 4
  • 5. Responsibilities and collaboration  Objects have responsibilities  This allows objects to interact, or collaborate, with each other  Program consists of objects which interact, just as real world entities interact  For example, in a real-world company each person has a job to do (responsibilities), and people collaborate to achieve the company’s aims Object Oriented Software Development 2. C# object oriented programming basics 5
  • 6. Encapsulation  Objects are able to collaborate through behaviour and attributes which are public  Objects can also have behaviour and attributes which are private  These are for the object itself to use in performing its responsibilities  Public behaviour may modify private attributes or use private behaviour  Collaborating objects do not need to know about these Object Oriented Software Development 2. C# object oriented programming basics 6
  • 7. Classes  May have more than one object of the same kind that have common characteristics  Class is a template for creating objects of the same kind  A bit like a job description for a real-world job  Employee class can be used to create many Employee objects  When we write the code we are actually writing the class definitions Object Oriented Software Development 2. C# object oriented programming basics 7
  • 8. Classes and objects  An object is a specific instance of a class  Class defines the attributes and methods which are common to all instances of class  Each object can have its own specific values for these attributes  Each Employee object will have a Name, but the value is different in each object  Objects are created from the class as the program runs Object Oriented Software Development 2. C# object oriented programming basics 8
  • 9. What’s in a class  A class is written as a named a block of code  Contains declarations of variables to represent the attributes  Contains blocks of code, nested within the class, to define the methods  Each method contains a sequence of steps which carry out the action which that method defines  Usually contains one or more constructors Object Oriented Software Development 2. C# object oriented programming basics 9
  • 10. C# class example code  OOBasicsDemo project  Employee.cs Object Oriented Software Development 2. C# object oriented programming basics 10
  • 11. Class diagrams Object Oriented Software Development 2. C# object oriented programming basics 11 class name attributes methods private – cannot be accessed by other objects public – can be accessed by other objects
  • 12. Object diagrams Object Oriented Software Development 2. C# object oriented programming basics 12 name = Michael username = michael currentLocation = loc phoneNumber = 1234 emp1 : Employee name = Susan username = susan currentLocation = loc phoneNumber = 4321 emp2 : Employee each object here is an instance of the Employee class with its own values for the attributes
  • 13. Variables  A variable is a name given to a piece of information in a program  Allows us write code which refers to and uses that information  Actual value will depend on what has happened as the program runs  May be different each time the program runs and may change as it runs Object Oriented Software Development 2. C# object oriented programming basics 13
  • 14. Declaring variables  In C# a variable needs to be declared before it can be used  Declaring a variable means specifying that a particular piece of information may exist by giving it a name and stating the type int myValue Declares a variable of type int with name “myValue” Object Oriented Software Development 2. C# object oriented programming basics 14
  • 15. Giving values to variables  Can assign a value to a variable, e.g. myValue = 3 myValue = x where x is another int variable myValue = 3x  Can assign at the same time as declaring, e.g int myValue = 3 Object Oriented Software Development 2. C# object oriented programming basics 15
  • 16. Object references  In an OO program, a variable can be an object reference  A name given to an object  Allows us write code which refers to and uses that object  Need to declare variable: Employee emp  Need to create an object and assign it to this variable Object Oriented Software Development 2. C# object oriented programming basics 16
  • 17. Instance variables  Attributes of an object are also known as instance variables or fields  prefer these as attribute has another meaning in C#  Each instance variable represents a piece of information of a specific type, which can be:  a C# built-in type, e.g. string, int  any .NET Framework type, e.g. DateTime (we will look at .NET types in more detail later)  any class in your application, e.g. Location (a class which would represent a work location) Object Oriented Software Development 2. C# object oriented programming basics 17
  • 18. C# creating objects example code  OOBasicsDemo project  Employee.cs  Program.cs Object Oriented Software Development 2. C# object oriented programming basics 18
  • 19. Creating objects example  Test program creates some objects and make them do something  Program.cs  Main method – entry point to a C# application  Creates object using new keyword  emp1, emp2 are object references each of which “points” to an object of type Employee Object Oriented Software Development 2. C# object oriented programming basics 19
  • 20. null references  A reference can be null  The reference is declared but does not actually point to an object Object Oriented Software Development 2. C# object oriented programming basics 20 reference declared, not assigned to object - null reference assigned to object reference no longer assigned to object - null
  • 21. Constructors  Constructor is executed when object is created to initialise object  Constructor is similar to a method, but must have same name as the class  Employee must have constructor with list of parameters which match information supplied Object Oriented Software Development 2. C# object oriented programming basics 21
  • 22. Constructors  Class can have more than one constructor, each with different parameter list  Employee has two constructors – one takes no parameters (default constructor) Object Oriented Software Development 2. C# object oriented programming basics 22
  • 23. C# messages example code  OOBasicsDemo project  Employee.cs  TimeSheet.cs  Program.cs Object Oriented Software Development 2. C# object oriented programming basics 23
  • 24. Messages  Collaborating objects interact with each other by sending messages  Message is simply the name of a method to be called on the receiving object  Information may be passed to receiving object as method parameter(s)  Reply may be passed back as method return value Object Oriented Software Development 2. C# object oriented programming basics 24
  • 25. Types of message  Messages sent to an object may :  Request information from that object  Method will return a value  Parameter(s) may provide further detail as to what information to return  Give an instruction to that object  Method will (usually) not return a value  Parameter(s) may provide further detail about instruction Object Oriented Software Development 2. C# object oriented programming basics 25
  • 26. Sending messages to objects  Send message by calling method  In example code, method of Employee sends message to a TimeSheet object to ask it to add an entry  Calls AddEntry method  Employee does not need to know how TimeSheet does this  Note that test program sends message to Employee object to start this off Object Oriented Software Development 2. C# object oriented programming basics 26
  • 27. Collaboration through messages  In this example the Employee object and TimeSheet object collaborate do perform the task of recording the information about hours worked  Employee object has knowledge of hours worked and responsibility for providing this information to the TimeSheet object  TimeSheet object has responsibility for actually storing the information Object Oriented Software Development 2. C# object oriented programming basics 27
  • 28. Sequence diagram Object Oriented Software Development 2. C# object oriented programming basics 28 Program emp1 ts RecordOvertime() AddEntry() object message time This diagram shows that Program calls RecordOvertime on Employee object emp1, which as a result calls AddEntry on TimeSheet object ts – look at code to see how this works
  • 29. Method signatures  Specify method name, return type and parameter types, e.g.:  RecordOvertime  Needs number of hours as a parameter  Needs TimeSheet object as a parameter  returns no value (return type is void)  Email  Returns a string containing the email address  Doesn’t need to pass any parameters Object Oriented Software Development 2. C# object oriented programming basics 29
  • 30. Class diagram with more detail Object Oriented Software Development 2. C# object oriented programming basics 30 attribute types parameters return type
  • 31. Methods and algorithms  A method contains code which defines the steps required to perform an action  Sometimes this can be very simple:  AddEntry method simply writes to console  RecordOvertime method just sends a message to another object  Sometimes the action is more complicated, and requires many steps to define an algorithm Object Oriented Software Development 2. C# object oriented programming basics 31
  • 32. Methods and algorithms  Algorithm is a step-by-step procedure to solve a problem  Steps are defined as program statements  May involve combination of any of the following:  Calculations  Decisions: if-else statements  Repeated actions: for, while loops  Calls to other methods Object Oriented Software Development 2. C# object oriented programming basics 32
  • 33. Relationships  Need to define relationships to allow objects to interact  Can show relationships in class and object diagrams  Need to implement these in code  Learn code patterns for implementing various relationship types Object Oriented Software Development 2. C# object oriented programming basics 33
  • 34. “has-a” relationship  One object contains one or more other objects  Department has Employees, Employee has-a Location  aggregation – shared ownership  composition – exclusive ownership  association – no ownership  Usually implemented as an instance variable in one class  Employee has an attribute of type Location Object Oriented Software Development 2. C# object oriented programming basics 34
  • 35. “uses-a” relationship  One object has some kind of association with another  Employee uses-a TimeSheet  Association is temporary, not implemented by instance variable  Can be implemented through a method parameter  Employee’s RecordOvertime method has a parameter of type TimeSheet Object Oriented Software Development 2. C# object oriented programming basics 35
  • 36. “is-a” relationship  Inheritance relationship  We will come back to this later... Object Oriented Software Development 2. C# object oriented programming basics 36
  • 37. C# relationships example code  OOBasicsDemo project  Employee.cs  Location.cs  TimeSheet.cs  Department.cs Object Oriented Software Development 2. C# object oriented programming basics 37
  • 38. Relationships in class diagram Object Oriented Software Development 2. C# object oriented programming basics 38 aggregation association (has-a) association (uses-a) Note that we are not showing the currentLocation attribute of type Location in the Employee class box now as it is implied by the relationship
  • 39. Relationships in object diagram Object Oriented Software Development 2. C# object oriented programming basics 39 name : string = Michael username : string = michael phoneNumber : string = 1234 emp1 : Employee name : string = Susan username : string = susan phoneNumber : string = 4321 emp2 : Employee loc : Location here there are two Employee objects associated with the same Location object “snapshot” of objects which exist at a point in time while the program runs
  • 40. Key OO concepts  Object  Class  Message  Relationship Object Oriented Software Development 2. C# object oriented programming basics 40
  • 41. What’s next?  Next we will look in more detail at the syntax of C# and how to write C# classes Object Oriented Software Development 2. C# object oriented programming basics 41
  • 42. Concepts  Object  Class  Message  Reusability  Encapsulation  Information hiding Object Oriented Software Development 2. C# object oriented programming basics 42