South Seattle College Interview Computer Science Lecture August 10
Objects:
- Primitive types and where we came from
- Higher level languages and abstraction
- Example code: vector calculus... points/vectors/planes
- Example code
- Look at the code: why abstraction
- Walk through code, what happens here
- Worksheet: expand on it
- generalize to N-dimensional operation, what additional info do you need?
- What is similar? what is different?
More details:
- (No code)
- start with very early programming: how did things look?
- way back to the early days of programming: Cobol, Basic, Fortran - everything was numbers and function calls
- operations on numbers, addresses of numbers
- used to be, you had to understand computers at a circuitry level to program them
- what's happened over the last 3 decades, is we're moved up to higher level
- concept called "abstraction" - details of how things work are hidden away, don't have to deal with it
- today, we're going to talk about how you do that in code
Objects
- objects are the way you implement abstraction in code - the way you hide away details
- it's a simple concept: an object is a collection of related data.
- AN OBJECT IS A COLLECTION OF RELATED DATA.
- That's it. But it's a very powerful idea.
Example:
- Since this idea of "abstraction" is, by definition, abstract, it's important to have a concrete example
- Let's start with this classes.py
- Start where it says to start: at the main function
- Very first line: we create a point.
- Dealing with primitive types, but now let's see how we introduce a class
- We have created a 3 dimensional point, and if we go back and review our vector calc, that point is defined by 3 distinct numbers
- Here we are defining a type of object, called a point - a collection of data, x, y, and z, have a general template so we can define multiple instances of this object
- And the point goes and stores those numbers in some particular way, we don't have to worry about it right now
- Here we have another object, a vector, which similarly stores a set of related numbers
- We have a plane object, which is defined by a set of related objects - a point and a vector
- Objects store related data - not just primitive data, data can also be other objects
Activity Question 1: what is this code doing?
- Form small group and discuss: what is this code doing?
- pretty clear, at a high level, that this code is finding shortest distance from point to plane
- objects: encapsulation: abstraction: this is what it looks like
Activity Question 2: extending the idea
- Right now, code was written for 3D vectors
- How would we change this to work for N-dimensional vectors?
5 5 5
| --------------------- | ------------------------- | ------------------ |
Objects, objects vs functions Vectors, vector ops, vector objects, brief review Activity/worksheet: * implementing solution to linear systems * what kind of objects would you need * what kind of data would store * what numbers we associate, primitive types * could do something more fun, like Netflix movie rating system * or do BOTH
Objects:
- contrast with functions
- primitive types
- representing data with numbers
- functions --> detail
- objects --> abstractions, higher level
- tie objects into computers/electronics generally
Objects:
- example
- vectors
- 2D
- 3D
- N-dimensional vector
- generalization - it doesn't matter how many dimensions
Objects:
- activity worksheet
- walk through instructions
- end lecture at worksheet