Announcements/Follow-ups P7 is posted, due Friday August 2 at 11pm - - PowerPoint PPT Presentation

announcements follow ups
SMART_READER_LITE
LIVE PREVIEW

Announcements/Follow-ups P7 is posted, due Friday August 2 at 11pm - - PowerPoint PPT Presentation

Announcements/Follow-ups P7 is posted, due Friday August 2 at 11pm No late period You can choose either FishPond or YearGoogol Secret Tests Follow-ups Bidirectional example fix: remove guava from build- path


slide-1
SLIDE 1

Announcements/Follow-ups

  • P7 is posted, due Friday August 2 at 11pm

– No late period – You can choose either FishPond or YearGoogol – Secret Tests

  • Follow-ups

– Bidirectional example fix: remove guava from build- path – StaticGenerics example – Finish Wednesday’s slides – ArrayList copy constructor and generic wild-card <?> – Year Googol background

slide-2
SLIDE 2

Inheritance and generics

  • Extends can be used with type Parameters

– LineUp<A extends Athlete>

  • Now A can’t be any type, only Athlete and its sub-types

– MyGeneric<T extends MyInterface>

  • “Extends” was chosen as the keyword in type-

parameterization, even for interfaces

  • When your class implements an interface, you write

“implements”

  • But when your interface is derived from a super-

interface, you write “extends”

  • ShapeList example
slide-3
SLIDE 3

Inheritance and generics

  • ArrayList copy constructor and <?>

– ShapeList again

  • Arrays are covariant, collections are not

– ArraysAndGenerics example

slide-4
SLIDE 4

Multiple Inheritance

Shape

3

px

Rhombus Rectangle

3

area

3

py px

2

py

2

area

3

px

3

py

Square

3

area

3

px

3

py

3

area class Square extends Rhombus, Rectangle {…}

  • Issues?
  • Supported in Java

for interfaces, but not classes

  • Supported for

classes in other languages, e.g. C++

slide-5
SLIDE 5

𝒘1 𝒘2

(1,6) (8,4) (8-1,4-6)=(7,-2) 𝑦 𝑧

Vector Arithmetic

slide-6
SLIDE 6

𝒒(𝑝𝑚𝑒)

(600,50)

𝒒(𝑜𝑓𝑥)

(50,400)

𝒒(𝑜𝑓𝑥)

(850,-200)

𝒒(𝑝𝑚𝑒)

Wrapping

slide-7
SLIDE 7

A B B B A A A B

𝒔𝐵𝐶=(-50-100,-200-50)=(-150,-250)

(100,50) (750,400) (-50,-200)

Shortest Path

slide-8
SLIDE 8

𝒔𝐵𝐶 𝑠

𝐵

𝑠𝐶 A B

Collision Detection

slide-9
SLIDE 9

(0,0,0) (1,0,0) (1,1,0) (0,1,0) (0,0,1) (1,0,1) (1,1,1) (0,1,1)

x y z

Hypercubes

slide-10
SLIDE 10

Linear Algebra and Physics

  • Matrix operations

– Entry-wise operations – Matrix dot product – Matrix multiplication – Rotation Matrices – Round-off error with floating-point arithmetic

  • Newtonian mechanics

– Velocity, acceleration, Newton’s laws – Gravitational force – Collision force

slide-11
SLIDE 11

Inheritance and Design

  • Issues with protected fields

– http://programmers.stackexchange.com/question s/162643/why-is-clean-code-suggesting-avoiding- protected-variables – Reduces encapsulation: sub-classes can expose internal state – YAGNI: “You aren’t gonna need it” – LSP: Liskov Substitution Principle – OCP: Open(for extension)/Closed(for modification) principle

slide-12
SLIDE 12

Inheritance and Design

  • Extension vs. Composition

– Extension: extending functionality of a super-class – Composition: wrapping another class in a field – BigInt example, ShapeList revisited

  • Style: code reuse with super

– Copy constructors – Standard Equals – Super examples

slide-13
SLIDE 13

Reflectance

  • The ability of your source code to “hold up a

mirror” and inspect itself.

  • Allows things like:

– Manipulating fields (including private ones) – Converting between source code and Strings

  • “BasicSoldier”
  • “ShinyCoin”
  • Requires certain execution environments

– Not available in Applets (used on the internet)

slide-14
SLIDE 14

The Class class

  • Represents a data-type

– Reference types: objects, enums – Primitive types

  • Is generic!
  • All constructors are private. Methods are used for

acquiring a Class object:

– myObj.getClass(); – myPrimitive.class; – Class.forName(“…”); – And more: Reflectance example

slide-15
SLIDE 15

The Reflection API

  • Acquiring Class objects is just the tip of the ice-

berg of a large API:

– myClass.newInstance(); //instantiates the class – myClass.getMethods(); //enumerates the methods – There is a Method class

  • myMethod.invoke(…);

– There is a Type class for generic type parameters – There is an Annotation class

  • @override
  • @Test