{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Data Structures and algorithms

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

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

View Full Document Right Arrow Icon
Click to edit Master subtitle style © 2009 Dr. Tim Margush 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 Document Right Arrow Icon
© 2009 Dr. Tim Margush 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 Margush 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 Document Right Arrow Icon
© 2009 Dr. Tim Margush 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 Margush 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 Document Right Arrow Icon
© 2009 Dr. Tim Margush 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 Margush 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 Document Right Arrow Icon
© 2009 Dr. Tim Margush 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 Margush Reuse - Generic Types Used to define a collection of classes that are similar, but depend on a yet- to-be-determined type public class MostlyKnown<T>{ something depends on an unknown type T }
Background image of page 9

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

View Full Document Right Arrow Icon
© 2009 Dr. Tim
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}