Introduction to Object-Oriented Programming and Computer Fundamentals

Introduction to Object-Oriented Programming and Computer Fundamentals
Slide Note
Embed
Share

In this lecture, we delve into the basics of computer systems, focusing on what a computer is and how it processes data. We also explore the significance of programming languages in modern software development, discussing procedural and functional programming paradigms. Learn about the role of machine code, the importance of abstraction in programming, and the distinctions between different programming approaches.

  • Object-Oriented Programming
  • Computer Fundamentals
  • Programming Paradigms
  • Machine Code
  • Abstraction

Uploaded on Feb 28, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. CMPU-102-51 Spring, 2020 Data Structures and Algorithms Lecture #1: Introduction to Object-Oriented Programming Rui Meireles Peter Lemieszewski 1

  2. Introduction to Object-Oriented Programming (IPUJ 1.1, 1.5) 2

  3. What is a computer? A machine that processes data: 1. Data resides in memory (e.g. hard drive) 2. Data is brought into the Central Processing Unit (CPU) 3. Data is operated on by the CPU 4. Operation results are saved to memory Each computer type supports a given set of operations/instructions Defined by its Instruction Set Architecture (ISA) Also known as machine code A computer program commands the computer to process data in a desired manner by specifying a sequence of such instructions E.g. let's add 2 numbers: What the computer does when executing a program: 1. load a 2. load b 3. add a, b, c 4. store c 3

  4. Programming languages Today, machine code isn't practical for meaningfully-large programs For efficiency, it is numerical and whitespace free, hence not human-readable Limited built-in functionality Programming languages make development easier Textual, human-readable Added features such as as data structures, type checking, libraries, etc Allow us to abstract away some of the details to focus on problem solving Programs must be translated into machine code before execution Can think of programming language as a user-friendly proxy for a computer Languages can be classified according to their paradigm (i.e. style) Programming paradigm defines overall pattern for code design Languages can be multi-paradigm (e.g. Scheme) ? 4

  5. Procedural programming Programs = data * procedures Procedures are sequences of instructions that accomplish a task Can have input and output (contrast with functions, which always have output) Can modify state that is external to them (i.e. have side effects) Procedures and state are decoupled Matches well with what the computer actually does: Data resides in memory, instructions operate on data It's a computer architecture-inspired paradigm Examples: Fortran, Cobol, Basic, Pascal, C New state Procedure call State marry(DoloresPointer) side effect Dolores data object Dolores data object 5

  6. Functional programming Programs = functions * functions Focuses on the flow of data, transformed from function to function Comes from mathematics (function theory) Tries to avoids external state/side effects, data object mutability Simplifies mathematical proofs (e.g. correctness proofs) Doesn't match computer architecture, making it slower Examples: Lisp, Scheme/Racket, ML, Scala, Haskell, etc marry(Dolores) Function call Married Dolores data object (different data object) Dolores data object 6

  7. Object-Oriented Programming (OOP) Programs as models of the real world Send messages between objects to simulate the temporal evolution of a set of real world phenomena Objects are the model building blocks (i.e. Lego pieces) Combine data/state and behavior, are composed of: Fields: object-specific data Methods: procedures that act upon the fields Provide encapsulation Programs = objects * messages Sending a message equates to calling a method Arguably the most popular paradigm nowadays Java, C++, C#, Python, Ruby, JavaScript, PHP, Objective-C, etc Person field: name method: sayYourName() 7

  8. OOP example State (fields) and behavior (methods) are coupled Same object but mutated Person object Dolores Method call/message setMarStatus(married) State State Field Value name: Dolores birthdate: 2/30/90 maritalStatus: single name: Dolores birthdate: 2/30/90 maritalStatus: married Methods Methods getAge() setMarStatus(newStatus) getAge() setMarStatus(newStatus) 8

  9. Classes Objects are instances of a more general category or class So we can share behavior and state structure amongst objects Person class instances of Dolores Teddy State name: _____________ birthdate: __________ maritalStatus: _______ name: Dolores birthdate: 2/30/90 maritalStatus: married name: Teddy birthdate: 9/31/91 maritalStatus: married Methods getAge() setMaritalStatus(newStatus) Classes encapsulate data and operations 9

  10. Inheritance Lets common behavior be shared while preserving specific traits Superclass: common; subclasses: specific Person name getName() Student Employee major getMajor() department getDepartment() Note: this is a UML (Unified Modeling Language) class diagram 10

  11. Polymorphism Different subclasses may implement the same operation differently E.g. a student s meal price depends on his meal plan, an employee s meal price is a fixed amount Polymorphism (from the Greek for "many forms") Allows us to use Person s getMealPrice(), and have the actual implementation vary according the actual subclass I.e. provides common interface, regardless of actual implementation Person getMealPrice() Student Employee getMealPrice() getMealPrice() 11

  12. The 3 pillars of OOP Encapsulation, inheritance, polymorphism The secret to OOP s success Provide for modularity, composability, extensibility, scalability, etc More and more important as project size grows 12

  13. In-class exercise: OOP modeling Give an example of a problem where inheritance and polymorphism would be helpful Example contexts: A drawing application An online bookstore selling both digital and physical books A videogame (e.g. a fighting game) 13

More Related Content