lecture8_generics_and_abstract_factory.pdf - CSC3380 Object Oriented Design Lecture 8 Generics and Abstract Factory Quiz Time Milestone 1 • Due in a

lecture8_generics_and_abstract_factory.pdf - CSC3380 Object...

This preview shows page 1 - 10 out of 39 pages.

CSC3380 Object Oriented Design Lecture 8: Generics and Abstract Factory
Image of page 1
Quiz Time
Image of page 2
Milestone 1 Due in a little over a week. You must have implemented all the easy features. Record yourself using OBS and demonstrate each easy feature, proving that it works: Many of you have features like “basic functional website”. Just show that all the links work and any log-in systems are functioning correctly.
Image of page 3
Questions?
Image of page 4
This class Generic Types The Abstract Factory
Image of page 5
Generics/Templates Generics and templates allow you to write code that works on different types without requiring inheritance. You’ve seen this before: ArrayList<type> in Java std::vector<type> in C++ Writing a generic class is like writing a regular class, except you use a “fake” type which is filled in when the generic is used. “Generic” is roughly equivalent to “Template that isn’t as powerful” (C++ templates are turing-complete, Java generics are not)
Image of page 6
A generic class public class Matrix< T extends Number > { private T[] cells; public void Add( Matrix<T> o ) {…} public void Mult( Matrix<T> o ) {…} public void Scale( T value ) {…} public T get( int i, int j ) { return cells[i]; } }
Image of page 7
Generic class explanation “T” is the generic type variable. When people use this class they will substitute a real type for T: Matrix<Float> or Matrix<BigDecimal> “T” is an arbitrary name. It could be called “M” or “CoolType” In order to know how T can be used, we say that it “Extends” Number. The Number class contains methods to convert to specific types of Number.
Image of page 8
What’s the point?
Image of page 9
Image of page 10

You've reached the end of your free preview.

Want to read all 39 pages?

  • Spring '09
  • Suptik

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors