announcements follow ups
play

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


  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

  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

  3. Inheritance and generics • ArrayList copy constructor and <?> – ShapeList again • Arrays are covariant, collections are not – ArraysAndGenerics example

  4. Multiple Inheritance class Square Shape extends py px 3 3 Rhombus, Rectangle {…} Rhombus Rectangle • Issues? py py px 2 px 3 0 3 • Supported in Java for interfaces, but area 3 area 2 not classes • Supported for Square classes in other py 3 px 3 languages, e.g. C++ area 3 3 area

  5. Vector Arithmetic (8-1,4-6)=(7,-2) 𝑦 𝒘 2 𝑧 𝒘 1 (8,4) (1,6)

  6. Wrapping 𝒒 (𝑜𝑓𝑥) (850,-200) 𝒒 (𝑝𝑚𝑒) (600,50) 𝒒 (𝑜𝑓𝑥) (50,400) 𝒒 (𝑝𝑚𝑒)

  7. Shortest Path B B (-50,-200) 𝒔 𝐵𝐶 =(-50-100,-200-50)=(-150,-250) A A (100,50) B B (750,400) A A

  8. Collision Detection B A 𝑠 𝑠 𝐶 𝐵 𝒔 𝐵𝐶

  9. z Hypercubes (0,1,1) (1,1,1) (1,0,1) (0,0,1) y (1,1,0) (0,1,0) x (0,0,0) (1,0,0)

  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

  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

  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

  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)

  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

  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

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend