SlideShare ist ein Scribd-Unternehmen logo
1 von 18
Introduction to Computer Science
Computer Programming
Lecture e
This material (Comp 4 Unit 4) was developed by Oregon Health & Science University, funded by the Department
of Health and Human Services, Office of the National Coordinator for Health Information Technology under
Award Number 90WT0001.
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/.
Computer Programming
Learning Objectives - 1
• Define the purpose of programming
languages (Lecture a)
• Differentiate between the different types of
programming languages and list
commonly used ones (Lecture a)
• Explain the compiling and interpreting
process for computer programs
(Lecture b)
2
Computer Programming
Learning Objectives - 2
• Learn basic programming concepts
including variable declarations,
assignment statements, expressions,
conditional statements and loops
(Lectures c, d)
• Describe advanced programming
concepts including objects and modularity
(Lecture e)
3
Object-Oriented Programming
• Object-oriented programming (OOP) is a
popular paradigm. Examples:
– C++, C#, Java, Python, Ruby
• Supports important software engineering
principles
• Graphical user interface (GUI)
programming naturally conforms to OOP
4
Objects
• Objects have:
– Identity (name)
– Attributes (instance variables)
– Behavior (methods)
• OOP is a way of organizing code
– Data and related methods stored together
• OOP allows for code reuse
– Modularity
– Inheritance
5
Classes vs. Objects
• Classes are the code definition for objects
• They are the "blueprint“ for objects
• Objects are created when the program
runs
– Instantiation
– Similar to declaring a variable
6
Procedural vs OOP - 1
Procedural Version
double circleArea(double
radius)
{
return
3.14*radius*radius; }
}
Procedure: radius is
passed into circleArea as
a parameter
Class: Radius is stored
with the CalcArea method
How to add circumference
calculation?
OOP (class) Version
class Circle
{
double radius;
void setRadius(double
rValue)
{
radius = rValue;
}
double calcArea()
{
return
3.14*radius*radius;
}
} 7
Procedural vs OOP - 2
Procedural Version
double circleArea(double
radius)
{
return
3.14*radius*radius; }
}
OOP (class) Version
class Circle
{
double radius;
void setRadius(double
rValue)
{
radius = rValue;
}
double calcArea()
{
return
3.14*radius*radius;
}
} 8
OOP Designs
• OOP programs are
designed using
tools
• Unified Modeling
Language (UML) is
very common
• Example for class
of BMICalculator Figure 1: class “BMICalculator”
(Hribar, 2011)
9
Inheritance
• Inheritance is a powerful feature of OOP
• Classes can inherit methods and instance
variables
• Makes coding less redundant
• Allows for polymorphism
10
UML Diagram: Inheritance
Figure 2: Sample UML diagram.
(Hribar, 2011)
11
Modularity
• Separation of code into components such
as objects
• Non-OOP languages implement
modularity
– Procedures
• Allows for
– Reuse of code
– Maintainability
12
Encapsulation
• Objects can declare methods and instance
variables to be private or public
– Typically, instance variables are private
– Some (all) methods are public
• Class definition controls
– Valid ranges for values
– Rules for setting values, calling methods
– Details of implementation are hidden
• Interface is public methods and documentation
13
Computer Programming
Summary – Lecture e
• This lecture introduced:
– Object-oriented programming
– Inheritance
– Modularity
– Encapsulation
– Differences between classes and objects
14
Computer Programming
Summary
• This unit covered:
– The purpose of programming languages
– Different types of programming languages
– The compilation/interpreter process
– Programming language constructs
– Object-oriented programming (OOP)
– How programs are designed and implemented
– What code looks like
– What objects are and why they are used
15
Computer Programming
References – 1 – Lecture e
References
Eck, D. (2011). Introduction to Programming Using Java (6th ed.). Retrieved from
http://math.hws.edu/javanotes/
Lesson: Object-Oriented Programming Concepts (2011). In The Java Tutorials. Retrieved
November 13, 2011. Available from
http://docs.oracle.com/javase/tutorial/java/concepts/.
Morley, D., & Parker, C.S. (2010). Chapter 13: Program Development and Programming
Languages. In Understanding Computers Today and Tomorrow, 12th Edition
introductory. Boston: Course Technology.
Parsons, J.J., & Oja, D. (2010). Chapter 12: Computer Programming. In New
Perspectives on Computer Concepts 2011: Comprehensive (13th ed.). Boston:
Course Technology.
Gosling, J. (1995, February). Java: An Overview. Reprinted in: Treichel, J. & Holzer, M.,
(Eds.). Sun Microsystems Laboratories: The First Ten Years 1991−2001. (7-2).
Sierra, K., & Bates, B. (2009). Head First Java (2nd Ed.). O’Reilly Media.
16
Computer Programming
References – 2 – Lecture e
Charts, Tables, Figures
Figure 1: BMI Calculator (Hribar, 2011)
Figure 2: Child classes inherit all methods and instance variables from parent class
(Hribar, 2011).
17
Introduction to Computer Science
Computer Programming
Lecture e
This material was developed by Oregon
Health & Science University, funded by the
Department of Health and Human Services,
Office of the National Coordinator for Health
Information Technology under Award
Number 90WT0001.
18

Weitere ähnliche Inhalte

Was ist angesagt?

Oop lec 2(introduction to object oriented technology)
Oop lec 2(introduction to object oriented technology)Oop lec 2(introduction to object oriented technology)
Oop lec 2(introduction to object oriented technology)
Asfand Hassan
 
Course outline [csc241 object oriented programming]
Course outline [csc241 object oriented programming]Course outline [csc241 object oriented programming]
Course outline [csc241 object oriented programming]
Asfand Hassan
 
Basics of Object Oriented Programming
Basics of Object Oriented ProgrammingBasics of Object Oriented Programming
Basics of Object Oriented Programming
Abhilash Nair
 

Was ist angesagt? (20)

Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented Technologies
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Object-Oriented Programming (OOP)
Object-Oriented Programming (OOP)Object-Oriented Programming (OOP)
Object-Oriented Programming (OOP)
 
C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]
 
[OOP - Lec 02] Why do we need OOP
[OOP - Lec 02] Why do we need OOP[OOP - Lec 02] Why do we need OOP
[OOP - Lec 02] Why do we need OOP
 
C# Summer course - Lecture 2
C# Summer course - Lecture 2C# Summer course - Lecture 2
C# Summer course - Lecture 2
 
Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)Programming Fundamentals With OOPs Concepts (Java Examples Based)
Programming Fundamentals With OOPs Concepts (Java Examples Based)
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
 
Oop lec 2(introduction to object oriented technology)
Oop lec 2(introduction to object oriented technology)Oop lec 2(introduction to object oriented technology)
Oop lec 2(introduction to object oriented technology)
 
Course outline [csc241 object oriented programming]
Course outline [csc241 object oriented programming]Course outline [csc241 object oriented programming]
Course outline [csc241 object oriented programming]
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 
Concepts of oops
Concepts of oopsConcepts of oops
Concepts of oops
 
Oops and c fundamentals
Oops and c fundamentals Oops and c fundamentals
Oops and c fundamentals
 
Procedural vs. object oriented programming
Procedural vs. object oriented programmingProcedural vs. object oriented programming
Procedural vs. object oriented programming
 
Data abstraction and object orientation
Data abstraction and object orientationData abstraction and object orientation
Data abstraction and object orientation
 
Basic concepts of oops
Basic concepts of oopsBasic concepts of oops
Basic concepts of oops
 
Basics of Object Oriented Programming
Basics of Object Oriented ProgrammingBasics of Object Oriented Programming
Basics of Object Oriented Programming
 
Inheritance : Extending Classes
Inheritance : Extending ClassesInheritance : Extending Classes
Inheritance : Extending Classes
 
Ayush oops
Ayush oopsAyush oops
Ayush oops
 
Concepts In Object Oriented Programming Languages
Concepts In Object Oriented Programming LanguagesConcepts In Object Oriented Programming Languages
Concepts In Object Oriented Programming Languages
 

Ähnlich wie Computer Programming - Lecture E

Object oriented-programming-in-c-sharp
Object oriented-programming-in-c-sharpObject oriented-programming-in-c-sharp
Object oriented-programming-in-c-sharp
Abefo
 
Improved Presentation and Facade Layer Operations for Software Engineering Pr...
Improved Presentation and Facade Layer Operations for Software Engineering Pr...Improved Presentation and Facade Layer Operations for Software Engineering Pr...
Improved Presentation and Facade Layer Operations for Software Engineering Pr...
Dr. Amarjeet Singh
 
Csc1100 elements of programming (revised july 2014) 120lh-2-student
Csc1100 elements of  programming (revised july 2014) 120lh-2-studentCsc1100 elements of  programming (revised july 2014) 120lh-2-student
Csc1100 elements of programming (revised july 2014) 120lh-2-student
IIUM
 
Lecture 1 uml with java implementation
Lecture 1 uml with java implementationLecture 1 uml with java implementation
Lecture 1 uml with java implementation
the_wumberlog
 

Ähnlich wie Computer Programming - Lecture E (20)

Ece 1322 programming_for_engineers_s1_201213(1)
Ece 1322 programming_for_engineers_s1_201213(1)Ece 1322 programming_for_engineers_s1_201213(1)
Ece 1322 programming_for_engineers_s1_201213(1)
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
17 pcds syllabus
17 pcds syllabus17 pcds syllabus
17 pcds syllabus
 
Computer Programming - Lecture C
Computer Programming - Lecture CComputer Programming - Lecture C
Computer Programming - Lecture C
 
Object oriented-programming-in-c-sharp
Object oriented-programming-in-c-sharpObject oriented-programming-in-c-sharp
Object oriented-programming-in-c-sharp
 
Introduction to programming languages part 2
Introduction to programming languages   part 2Introduction to programming languages   part 2
Introduction to programming languages part 2
 
3350703
33507033350703
3350703
 
Chapter no 1
Chapter no 1Chapter no 1
Chapter no 1
 
Objc
ObjcObjc
Objc
 
Programming in c (pokhara university)
Programming in c (pokhara university)Programming in c (pokhara university)
Programming in c (pokhara university)
 
C programming
C programmingC programming
C programming
 
Student handbook xii
Student handbook xiiStudent handbook xii
Student handbook xii
 
Object Oriented Programming Overview for the PeopleSoft Developer
Object Oriented Programming Overview for the PeopleSoft DeveloperObject Oriented Programming Overview for the PeopleSoft Developer
Object Oriented Programming Overview for the PeopleSoft Developer
 
OOP Java
OOP JavaOOP Java
OOP Java
 
Core java part1
Core java  part1Core java  part1
Core java part1
 
Improved Presentation and Facade Layer Operations for Software Engineering Pr...
Improved Presentation and Facade Layer Operations for Software Engineering Pr...Improved Presentation and Facade Layer Operations for Software Engineering Pr...
Improved Presentation and Facade Layer Operations for Software Engineering Pr...
 
History Of C Essay
History Of C EssayHistory Of C Essay
History Of C Essay
 
Csc1100 elements of programming (revised july 2014) 120lh-2-student
Csc1100 elements of  programming (revised july 2014) 120lh-2-studentCsc1100 elements of  programming (revised july 2014) 120lh-2-student
Csc1100 elements of programming (revised july 2014) 120lh-2-student
 
Lecture 1 uml with java implementation
Lecture 1 uml with java implementationLecture 1 uml with java implementation
Lecture 1 uml with java implementation
 
Shuzworld Analysis
Shuzworld AnalysisShuzworld Analysis
Shuzworld Analysis
 

Mehr von CMDLearning

Mehr von CMDLearning (20)

What is Health Informatics - Lecture B
What is Health Informatics - Lecture BWhat is Health Informatics - Lecture B
What is Health Informatics - Lecture B
 
Evolution of and Trends in Health Care - Lecture D
Evolution of and Trends in Health Care - Lecture DEvolution of and Trends in Health Care - Lecture D
Evolution of and Trends in Health Care - Lecture D
 
Evolution of and Trends in Health Care - Lecture C
Evolution of and Trends in Health Care - Lecture CEvolution of and Trends in Health Care - Lecture C
Evolution of and Trends in Health Care - Lecture C
 
Evolution of and Trends in Health Care - Lecture B
Evolution of and Trends in Health Care - Lecture BEvolution of and Trends in Health Care - Lecture B
Evolution of and Trends in Health Care - Lecture B
 
Evolution of and Trends in Health Care - Lecture A
Evolution of and Trends in Health Care - Lecture AEvolution of and Trends in Health Care - Lecture A
Evolution of and Trends in Health Care - Lecture A
 
Public Healthcare (Part 2) Lecture C
Public Healthcare (Part 2) Lecture CPublic Healthcare (Part 2) Lecture C
Public Healthcare (Part 2) Lecture C
 
Public Healthcare (Part 2) Lecture B
Public Healthcare (Part 2) Lecture BPublic Healthcare (Part 2) Lecture B
Public Healthcare (Part 2) Lecture B
 
Public Healthcare (Part 2) Lecture A
Public Healthcare (Part 2) Lecture APublic Healthcare (Part 2) Lecture A
Public Healthcare (Part 2) Lecture A
 
Public Health (Part 1) Lecture C
Public Health (Part 1) Lecture CPublic Health (Part 1) Lecture C
Public Health (Part 1) Lecture C
 
Public Health (Part 1) Lecture B
Public Health (Part 1) Lecture BPublic Health (Part 1) Lecture B
Public Health (Part 1) Lecture B
 
Public Health (Part 1) Lecture A
Public Health (Part 1) Lecture APublic Health (Part 1) Lecture A
Public Health (Part 1) Lecture A
 
Regulating Healthcare - Lecture E
Regulating Healthcare - Lecture ERegulating Healthcare - Lecture E
Regulating Healthcare - Lecture E
 
Regulating Healthcare - Lecture D
Regulating Healthcare - Lecture DRegulating Healthcare - Lecture D
Regulating Healthcare - Lecture D
 
Regulating Healthcare - Lecture C
Regulating Healthcare - Lecture CRegulating Healthcare - Lecture C
Regulating Healthcare - Lecture C
 
Regulating Healthcare - Lecture A
Regulating Healthcare - Lecture ARegulating Healthcare - Lecture A
Regulating Healthcare - Lecture A
 
Regulating Healthcare - Lecture B
Regulating Healthcare - Lecture BRegulating Healthcare - Lecture B
Regulating Healthcare - Lecture B
 
Financing Healthcare (Part 2) Lecture C
Financing Healthcare (Part 2) Lecture CFinancing Healthcare (Part 2) Lecture C
Financing Healthcare (Part 2) Lecture C
 
Financing Healthcare (Part 2) Lecture B
Financing Healthcare (Part 2) Lecture BFinancing Healthcare (Part 2) Lecture B
Financing Healthcare (Part 2) Lecture B
 
Financing Healthcare (Part 2) Lecture A
Financing Healthcare (Part 2) Lecture AFinancing Healthcare (Part 2) Lecture A
Financing Healthcare (Part 2) Lecture A
 
Financing Healthcare (Part 2) Lecture D
Financing Healthcare (Part 2) Lecture DFinancing Healthcare (Part 2) Lecture D
Financing Healthcare (Part 2) Lecture D
 

Kürzlich hochgeladen

Patna Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Patna Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real MeetPatna Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Patna Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Call Girls Service
 
neemuch Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
neemuch Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meetneemuch Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
neemuch Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Call Girls Service
 
Mathura Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Mathura Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real MeetMathura Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Mathura Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Call Girls Service
 
Premium Call Girls Bangalore {7304373326} ❤️VVIP POOJA Call Girls in Bangalor...
Premium Call Girls Bangalore {7304373326} ❤️VVIP POOJA Call Girls in Bangalor...Premium Call Girls Bangalore {7304373326} ❤️VVIP POOJA Call Girls in Bangalor...
Premium Call Girls Bangalore {7304373326} ❤️VVIP POOJA Call Girls in Bangalor...
Sheetaleventcompany
 
Muzaffarpur Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Muzaffarpur Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real MeetMuzaffarpur Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Muzaffarpur Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Call Girls Service
 
9316020077📞Goa Call Girls Numbers, Call Girls Whatsapp Numbers Goa
9316020077📞Goa  Call Girls  Numbers, Call Girls  Whatsapp Numbers Goa9316020077📞Goa  Call Girls  Numbers, Call Girls  Whatsapp Numbers Goa
9316020077📞Goa Call Girls Numbers, Call Girls Whatsapp Numbers Goa
russian goa call girl and escorts service
 
Call Girls in Udaipur Girija Udaipur Call Girl ✔ VQRWTO ❤️ 100% offer with...
Call Girls in Udaipur  Girija  Udaipur Call Girl  ✔ VQRWTO ❤️ 100% offer with...Call Girls in Udaipur  Girija  Udaipur Call Girl  ✔ VQRWTO ❤️ 100% offer with...
Call Girls in Udaipur Girija Udaipur Call Girl ✔ VQRWTO ❤️ 100% offer with...
mahaiklolahd
 
Thoothukudi Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Thoothukudi Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real MeetThoothukudi Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Thoothukudi Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Call Girls Service
 
Russian Call Girls in Noida Pallavi 9711199171 High Class Call Girl Near Me
Russian Call Girls in Noida Pallavi 9711199171 High Class Call Girl Near MeRussian Call Girls in Noida Pallavi 9711199171 High Class Call Girl Near Me
Russian Call Girls in Noida Pallavi 9711199171 High Class Call Girl Near Me
mriyagarg453
 
VIP Call Girls Noida Sia 9711199171 High Class Call Girl Near Me
VIP Call Girls Noida Sia 9711199171 High Class Call Girl Near MeVIP Call Girls Noida Sia 9711199171 High Class Call Girl Near Me
VIP Call Girls Noida Sia 9711199171 High Class Call Girl Near Me
mriyagarg453
 
bhubaneswar Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
bhubaneswar Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meetbhubaneswar Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
bhubaneswar Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Call Girls Service
 
Thrissur Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Thrissur Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real MeetThrissur Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Thrissur Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Call Girls Service
 
Rajkot Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Rajkot Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real MeetRajkot Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Rajkot Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Call Girls Service
 
Bhagalpur Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Bhagalpur Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real MeetBhagalpur Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Bhagalpur Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Call Girls Service
 
Nanded Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Nanded Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real MeetNanded Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Nanded Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Call Girls Service
 
Top 20 Famous Indian Female Pornstars Name List 2024
Top 20 Famous Indian Female Pornstars Name List 2024Top 20 Famous Indian Female Pornstars Name List 2024
Top 20 Famous Indian Female Pornstars Name List 2024
Sheetaleventcompany
 
kochi Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
kochi Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meetkochi Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
kochi Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Call Girls Service
 

Kürzlich hochgeladen (20)

❤️Call girls in Jalandhar ☎️9876848877☎️ Call Girl service in Jalandhar☎️ Jal...
❤️Call girls in Jalandhar ☎️9876848877☎️ Call Girl service in Jalandhar☎️ Jal...❤️Call girls in Jalandhar ☎️9876848877☎️ Call Girl service in Jalandhar☎️ Jal...
❤️Call girls in Jalandhar ☎️9876848877☎️ Call Girl service in Jalandhar☎️ Jal...
 
Patna Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Patna Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real MeetPatna Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Patna Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
 
neemuch Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
neemuch Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meetneemuch Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
neemuch Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
 
Mathura Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Mathura Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real MeetMathura Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Mathura Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
 
Premium Call Girls Bangalore {7304373326} ❤️VVIP POOJA Call Girls in Bangalor...
Premium Call Girls Bangalore {7304373326} ❤️VVIP POOJA Call Girls in Bangalor...Premium Call Girls Bangalore {7304373326} ❤️VVIP POOJA Call Girls in Bangalor...
Premium Call Girls Bangalore {7304373326} ❤️VVIP POOJA Call Girls in Bangalor...
 
Muzaffarpur Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Muzaffarpur Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real MeetMuzaffarpur Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Muzaffarpur Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
 
9316020077📞Goa Call Girls Numbers, Call Girls Whatsapp Numbers Goa
9316020077📞Goa  Call Girls  Numbers, Call Girls  Whatsapp Numbers Goa9316020077📞Goa  Call Girls  Numbers, Call Girls  Whatsapp Numbers Goa
9316020077📞Goa Call Girls Numbers, Call Girls Whatsapp Numbers Goa
 
Call Girls in Udaipur Girija Udaipur Call Girl ✔ VQRWTO ❤️ 100% offer with...
Call Girls in Udaipur  Girija  Udaipur Call Girl  ✔ VQRWTO ❤️ 100% offer with...Call Girls in Udaipur  Girija  Udaipur Call Girl  ✔ VQRWTO ❤️ 100% offer with...
Call Girls in Udaipur Girija Udaipur Call Girl ✔ VQRWTO ❤️ 100% offer with...
 
Thoothukudi Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Thoothukudi Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real MeetThoothukudi Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Thoothukudi Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
 
Russian Call Girls in Noida Pallavi 9711199171 High Class Call Girl Near Me
Russian Call Girls in Noida Pallavi 9711199171 High Class Call Girl Near MeRussian Call Girls in Noida Pallavi 9711199171 High Class Call Girl Near Me
Russian Call Girls in Noida Pallavi 9711199171 High Class Call Girl Near Me
 
VIP Call Girls Noida Sia 9711199171 High Class Call Girl Near Me
VIP Call Girls Noida Sia 9711199171 High Class Call Girl Near MeVIP Call Girls Noida Sia 9711199171 High Class Call Girl Near Me
VIP Call Girls Noida Sia 9711199171 High Class Call Girl Near Me
 
bhubaneswar Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
bhubaneswar Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meetbhubaneswar Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
bhubaneswar Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
 
Thrissur Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Thrissur Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real MeetThrissur Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Thrissur Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
 
Rajkot Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Rajkot Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real MeetRajkot Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Rajkot Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
 
Dehradun Call Girls 8854095900 Call Girl in Dehradun Uttrakhand
Dehradun Call Girls 8854095900 Call Girl in Dehradun  UttrakhandDehradun Call Girls 8854095900 Call Girl in Dehradun  Uttrakhand
Dehradun Call Girls 8854095900 Call Girl in Dehradun Uttrakhand
 
Bhagalpur Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Bhagalpur Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real MeetBhagalpur Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Bhagalpur Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
 
Nanded Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Nanded Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real MeetNanded Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
Nanded Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
 
Top 20 Famous Indian Female Pornstars Name List 2024
Top 20 Famous Indian Female Pornstars Name List 2024Top 20 Famous Indian Female Pornstars Name List 2024
Top 20 Famous Indian Female Pornstars Name List 2024
 
Independent Call Girls Hyderabad 💋 9352988975 💋 Genuine WhatsApp Number for R...
Independent Call Girls Hyderabad 💋 9352988975 💋 Genuine WhatsApp Number for R...Independent Call Girls Hyderabad 💋 9352988975 💋 Genuine WhatsApp Number for R...
Independent Call Girls Hyderabad 💋 9352988975 💋 Genuine WhatsApp Number for R...
 
kochi Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
kochi Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meetkochi Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
kochi Call Girls 👙 6297143586 👙 Genuine WhatsApp Number for Real Meet
 

Computer Programming - Lecture E

  • 1. Introduction to Computer Science Computer Programming Lecture e This material (Comp 4 Unit 4) was developed by Oregon Health & Science University, funded by the Department of Health and Human Services, Office of the National Coordinator for Health Information Technology under Award Number 90WT0001. This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/.
  • 2. Computer Programming Learning Objectives - 1 • Define the purpose of programming languages (Lecture a) • Differentiate between the different types of programming languages and list commonly used ones (Lecture a) • Explain the compiling and interpreting process for computer programs (Lecture b) 2
  • 3. Computer Programming Learning Objectives - 2 • Learn basic programming concepts including variable declarations, assignment statements, expressions, conditional statements and loops (Lectures c, d) • Describe advanced programming concepts including objects and modularity (Lecture e) 3
  • 4. Object-Oriented Programming • Object-oriented programming (OOP) is a popular paradigm. Examples: – C++, C#, Java, Python, Ruby • Supports important software engineering principles • Graphical user interface (GUI) programming naturally conforms to OOP 4
  • 5. Objects • Objects have: – Identity (name) – Attributes (instance variables) – Behavior (methods) • OOP is a way of organizing code – Data and related methods stored together • OOP allows for code reuse – Modularity – Inheritance 5
  • 6. Classes vs. Objects • Classes are the code definition for objects • They are the "blueprint“ for objects • Objects are created when the program runs – Instantiation – Similar to declaring a variable 6
  • 7. Procedural vs OOP - 1 Procedural Version double circleArea(double radius) { return 3.14*radius*radius; } } Procedure: radius is passed into circleArea as a parameter Class: Radius is stored with the CalcArea method How to add circumference calculation? OOP (class) Version class Circle { double radius; void setRadius(double rValue) { radius = rValue; } double calcArea() { return 3.14*radius*radius; } } 7
  • 8. Procedural vs OOP - 2 Procedural Version double circleArea(double radius) { return 3.14*radius*radius; } } OOP (class) Version class Circle { double radius; void setRadius(double rValue) { radius = rValue; } double calcArea() { return 3.14*radius*radius; } } 8
  • 9. OOP Designs • OOP programs are designed using tools • Unified Modeling Language (UML) is very common • Example for class of BMICalculator Figure 1: class “BMICalculator” (Hribar, 2011) 9
  • 10. Inheritance • Inheritance is a powerful feature of OOP • Classes can inherit methods and instance variables • Makes coding less redundant • Allows for polymorphism 10
  • 11. UML Diagram: Inheritance Figure 2: Sample UML diagram. (Hribar, 2011) 11
  • 12. Modularity • Separation of code into components such as objects • Non-OOP languages implement modularity – Procedures • Allows for – Reuse of code – Maintainability 12
  • 13. Encapsulation • Objects can declare methods and instance variables to be private or public – Typically, instance variables are private – Some (all) methods are public • Class definition controls – Valid ranges for values – Rules for setting values, calling methods – Details of implementation are hidden • Interface is public methods and documentation 13
  • 14. Computer Programming Summary – Lecture e • This lecture introduced: – Object-oriented programming – Inheritance – Modularity – Encapsulation – Differences between classes and objects 14
  • 15. Computer Programming Summary • This unit covered: – The purpose of programming languages – Different types of programming languages – The compilation/interpreter process – Programming language constructs – Object-oriented programming (OOP) – How programs are designed and implemented – What code looks like – What objects are and why they are used 15
  • 16. Computer Programming References – 1 – Lecture e References Eck, D. (2011). Introduction to Programming Using Java (6th ed.). Retrieved from http://math.hws.edu/javanotes/ Lesson: Object-Oriented Programming Concepts (2011). In The Java Tutorials. Retrieved November 13, 2011. Available from http://docs.oracle.com/javase/tutorial/java/concepts/. Morley, D., & Parker, C.S. (2010). Chapter 13: Program Development and Programming Languages. In Understanding Computers Today and Tomorrow, 12th Edition introductory. Boston: Course Technology. Parsons, J.J., & Oja, D. (2010). Chapter 12: Computer Programming. In New Perspectives on Computer Concepts 2011: Comprehensive (13th ed.). Boston: Course Technology. Gosling, J. (1995, February). Java: An Overview. Reprinted in: Treichel, J. & Holzer, M., (Eds.). Sun Microsystems Laboratories: The First Ten Years 1991−2001. (7-2). Sierra, K., & Bates, B. (2009). Head First Java (2nd Ed.). O’Reilly Media. 16
  • 17. Computer Programming References – 2 – Lecture e Charts, Tables, Figures Figure 1: BMI Calculator (Hribar, 2011) Figure 2: Child classes inherit all methods and instance variables from parent class (Hribar, 2011). 17
  • 18. Introduction to Computer Science Computer Programming Lecture e This material was developed by Oregon Health & Science University, funded by the Department of Health and Human Services, Office of the National Coordinator for Health Information Technology under Award Number 90WT0001. 18

Hinweis der Redaktion

  1. Welcome to Introduction to Computer Science: Computer Programming. This is lecture e. The component, Introduction to Computer Science, provides a basic overview of computer architecture; data organization, representation, and structure; structure of programming languages; networking, and data communication. It also includes the basic terminology of computing.
  2. The learning objectives for this unit, Computer Programming, are to: Define the purpose of programming languages. Differentiate between the different types of programming languages and list commonly used ones. Explain the compiling and interpreting process for computer programs.
  3. Learn basic programming concepts including variable declarations, assignment statements, expressions, conditional statements, and loops. And describe advanced programming concepts including objects and modularity.
  4. This lecture focuses on advanced programming concepts. Object-oriented programming, or OOP, is a programming paradigm that is very popular today. Languages like C++, C#, Java, Python, and Ruby are object-oriented. OOP was first used in the 1960s but did not become popular until the 1980s and 1990s. Its popularity can be attributed to several factors. First, it supports software engineering principles of modularity, which makes the programs easier to develop and maintain. Second, most commercial applications developed today contain a graphical user interface, or GUI, for short. GUIs are composed of windows, buttons, and other widgets that are naturally expressed as objects. For that reason, many of the libraries that support GUI programming, for example, Windows Application Programming Interfaces, or APIs, are written in OOP languages.
  5. Objects in programming are similar to objects in our natural world. Objects have an identity; they are all called something, like "chair" or "desk“, so that people can refer to them. Similarly, each object in a computer program has a name corresponding to a unique memory location where the object is stored. Natural objects have attributes; for example, a chair has attributes like height, color, and position. Objects in programs have data associated with them called instance variables. Finally, objects have behavior; behavior means “the things that objects can do”. Most people do not necessarily think that a chair has behavior, but it does – it supports the person sitting in it. Similarly, objects in programs have behavior – these are the methods that are defined for the object. OOP is just one of many programming paradigms. It is one way of expressing a program for a given problem, but it is certainly not the only way. It is helpful to think of OOP as a way of organizing a program so that the data and related methods are stored together. This particular type of organization allows for code re-use, both because it is modular but also because it allows for something called inheritance. Inheritance means that objects or classes inherit data and/or methods from other classes. This allows for less code redundancy.
  6. It is important to understand some terminology with respect to objects. Objects are not created until a program runs. Writing code for objects involves classes. Classes are the code definition for objects and are considered the blueprints for an object. When a class is used – meaning an object of a class is created – the class instantiates that object. It is similar to declaring a variable except that the data type is the class type, instead of a primitive type for a variable.
  7. Here are two different ways to write a code segment that calculates the area of a circle. The left presents a procedure that has been defined to do this. It has an input parameter for the radius and returns the calculated value of the area, pi times radius squared. On the right side of the slide is a class that has been defined for a circle. It has an instance variable that stores the radius and has two methods – one to set the value of the radius and one to calculate the area of the circle. Note that the “calculateArea” method does NOT need any input parameters since it stores the value of the radius in the instance variable. From this example, it is not clear that either approach is better than the other. But suppose it is necessary to add a method that will calculate the circumference of the circle.
  8. To implement the procedural programming approach, we would add another procedure for the circumference calculation. Once again, it would be necessary to have an input parameter for the radius, or diameter. For the OOP approach, just add another method to the Circle class. Nothing else would need to be changed, and this method would not need input parameters, since it would use the value of the instance variable radius in the calculation. To calculate both the area and circumference of the same circle, in other words, for the same radius, it probably makes more sense to program the solution using the Circle class. This would store the two methods together along with the radius.
  9. OOP programs are often designed using tools such as Unified Modeling Language, or UML. A UML diagram gives the basics about the class – the name; the attributes, also known as instance variables; and the methods. This is very useful when building a design with all the classes in a program. It gives a snapshot of how the different classes are related and what they do. On the right side of the slide is an example design for a class called “BMICalculator.” In this class, assume three instance variables – doubles that store the weight, height, and body mass index, or BMI, for the class. Now, assume the following methods for this class: “setWeight” - sets the value of the weight instance variable “setHeight” - sets the value of the height instance variable “calcBMI” - calculates the BMI and stores it in the bmi instance variable “outputBMI” - prints the value of the bmi instance variable to the screen “outputBMICategory,” - which outputs to the screen the weight category for the BMI that is stored in the instance variable Note that this design is NOT for the program written in the previous two lectures for calculating BMI. That program was a simple program that did not include any classes with instance variables and methods, just a class with a main method. Instead, this is what a class might look like if a class were to be used for calculating BMI.
  10. Inheritance is a very powerful feature of OOP. It allows us to define classes based on the definitions of other classes. Classes can inherit methods and/or instance variables from another class. This allows for a lot less code redundancy because it defines instance variables and methods for a class that can be included in many other classes without having to rewrite them in the other class definitions. Another powerful feature of inheritance is polymorphism. This is a concept that is difficult to understand in the abstract; the basic idea is that the same method call will trigger different methods to run, based on the class type of the object. It is not necessary to understand polymorphism at this time, but it is important to know that it is possible with OOP and inheritance.
  11. Here's a sample UML diagram that shows inheritance. In this diagram, the base class or the parent class is the “BankingAccount” class. It has two instance variables defined – one for the account number and the other for the balance of the account. It also has four methods – one to set the value of the account number; another to set the value of balance; a third to get the value of balance; and finally, a fourth method to print all the account information to the screen. There are two child classes: “CheckingAccount” and “SavingsAccount.” These two child classes inherit all the methods and instance variables from their parent “BankingAccount,” but they also add more instance variables and methods to their classes. For example, “CheckingAccount” has three instance variables – the two inherited ones from “Banking Account” and one defined specifically for it, named overdraft. Similarly, it has six methods – four that it inherited plus the two that are defined for it, named “setOverdraft” and “getOverdraft”. “SavingsAccount” inherits the two instance variables from “BankingAccount” and has one additional one – “interestRate.” It also inherits four methods and has two additional methods – “setInterestRate” and “accrueInterest.” The important concept to remember about inheritance is that the base class or the parent class defines instance variables and methods that are inherited by the child classes. This eliminates the need for the child classes to redefine these instance variables and methods in their own classes, which leads to less code redundancy. But, the child classes can also add their own instance variables and/or methods to the inherited ones. In this example, both “CheckingAccount” and “SavingsAccount” have instance variables named “accountNum” and “Balance”, but only “CheckingAccount” has an instance variable named “Overdraft”—“SavingsAccount” does not have this instance variable. Similarly, the “SavingsAccount” class has an instance variable “interestRate” that the “CheckingAccount” class does not.
  12. Modularity is the separation of code into individual components. Objects provide modularity in OOP languages, but non–OOP languages support modularity, too. Procedures, subroutines, and functions are all examples of modules in code. The purpose of modularity is to organize the code into separate components, each of which accomplishes a particular task. This allows for code reuse – the component is defined once but can be called many times. Also, when the program is divided into components, it is easier to maintain and comprehend the code. Any changes to one component will have minimal effects on other components. Also, if changes to the program are required, it is easier to identify which component needs to be modified since each component has its own purpose. For example, if the format of a program's output is incorrect, the programmer would know to look at the component that produces output.
  13. Encapsulation builds on modularity to provide what is called "information hiding". Objects can specify whether instance variables and methods are public or private. If they are private, they cannot be accessed directly outside of the class. Typically, instance variables are private and some or all methods are public. When an instance variable is private, it cannot be accessed from outside the class, which prevents other code from changing its value. Instead, the class will provide public methods that can change or retrieve the value of the instance variable. When a class or object is well-encapsulated, the details of the implementation of the class are hidden from any other code that will use that class. Also, instance variables can be changed and accessed only by the public methods of the class. These public methods control what valid values are for the instance variables and when the methods can be called. If the variables were public and could be modified by any code, there would be no guarantee that the values were valid. For example, if there is an instance variable of a well-encapsulated class that is used as the denominator of a fraction, the methods that set this value could ensure that it was never set to zero. If the class were not well-encapsulated – say, the instance variable was public and could be changed by any code – there would no longer be a guarantee that the instance variable was not zero. Any other code that uses this class accesses only what is called the interface of the class. This interface is made up of the public methods of the class and any documentation about the class. When accessing the interface, the focus is only on the details needed to use the class, not on how the class is implemented.
  14. This concludes lecture e of Computer Programming. This lecture introduced object-oriented programming and concepts such as inheritance, modularity and encapsulation. The lecture also described the differences between classes and objects.
  15. This also concludes the unit titled Computer Programming. This unit presented the purpose of programming languages, the different types of programming languages, how a program is compiled or interpreted, what common programming language constructs are, particularly in Java, and what OOP is. This unit also offered an understanding of how programs are designed and implemented, what code looks like, and what objects are and why they are used.
  16. References slide. No audio.
  17. References slide. No audio.
  18. No audio.