Data Structures and algorithms

Data Structures and algorithms - OOP: Class Design Elick to...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Click to edit Master subtitle style © 2009 Dr. Tim OOP: Class Design Essentials Dr. Tim Margush University of Akron © 2009
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
© 2009 Dr. Tim Goals Review intermediate class design concepts in Java Composition Inheritance Polymorphism Introduce other class design concepts Generics Abstract classes and Interfaces
Background image of page 2
© 2009 Dr. Tim Encapsulation Collecting related details in a single class Hiding implementation details from clients Providing a usable public interface Thinking ahead toward reusability Define protected members appropriately Consider package access Include useful methods not immediately
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
© 2009 Dr. Tim isahasa Subclassing is used when objects of the new class can also be considered members of the superclass – that is, they exhibit the IS A relationship Square, Rhombus, Triangle are subclasses of Polygon. A Square IS A Polygon A Rhombus IS A Polygon A jPanel IS A jComponent Class composition is used when an object of one class has an object as a member. Many class definitions include objects of another class An ArrayList HAS A n elementData (Object[]) A String HAS A value (char[]) A Human HAS A name (String)
Background image of page 4
© 2009 Dr. Tim Extending With Composition Embed a useful object inside your class private Create public methods with desired functionality Implement the methods using existing methods of the hidden object
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
© 2009 Dr. Tim Composition Example class SortedList { private PlainList list = new PlainList(); public boolean add (String s){ int loc = findNextLarger(s); return list. add (s, loc); } public boolean hasNext (){ return list. hasNext (); } public String next (){ return list. next (); } private int findNextLarger(String s){ } }
Background image of page 6
© 2009 Dr. Tim Subclassing/Inheritance Extending, enhancing, customizing an existing class The subclass can inherit state and methods from the superclass The subclass can add variables and methods, and can override inherited methods Extending classes creates a hierarchy
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
© 2009 Dr. Tim Subclassing Example class SortedList extends PlainList { @override public boolean add (String s, int loc){ throw new OperationNotSupportedException(); return false; } public boolean add (String s){ int loc = findNextLarger(s); return super.add (s, loc); } private int findNextLarger(String s){ } }
Background image of page 8
© 2009 Dr. Tim Reuse - Generic Types Used to define a collection of classes that are similar, but depend on a yet-
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/22/2011 for the course CS 463 taught by Professor Dr. tim margush during the Fall '09 term at The University of Akron.

Page1 / 28

Data Structures and algorithms - OOP: Class Design Elick to...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online