Inheritance

Inheritance - Computer Science 340...

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

View Full Document Right Arrow Icon
1 Computer Science 340 Inheritance
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Class reuse Two forms of class reuse: Class inheritance Object composition A B A B Inheritance Composition
Background image of page 2
3 Inheritance-based reuse example: Application Frameworks Application Frameworks consist of code libraries and tools that implement a pre-made application architecture Major subsystems and components Interfaces between them and patterns of interaction Framework provides common functionality needed by all applications Developers plug in app-specific functionality in the right places to customize the framework for their application Frameworks typically implement common functionality in base classes that can be subclassed by app developers to integrate app-specific functionality MFCDocument MFCView MFCApplication NetworkWindow NetworkApplication NetworkDocument DiscoveryView 1..* 1 1 * MFCWindow 1 1 BrowseView TopologyView
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Inheritance-based reuse example: Application Frameworks Framework Demo: Microsoft Foundation Classes (MFC) Visual Studio generates code for a functional Windows application MFC base classes provide a lot of standard Windows functionality, and define specific integration points for app-specific code Subclasses provide app-specific functionality MFCDocument MFCView MFCApplication NetworkWindow NetworkApplication NetworkDocument DiscoveryView 1..* 1 1 * MFCWindow 1 1 BrowseView TopologyView
Background image of page 4
5 Choosing between Composition and Inheritance What type of relationship is being modeled? B “has-a” A => composition B “uses-a” A => composition B “is-a” A => inheritance (usually)
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Choosing between Composition and Inheritance “Favor object composition over class inheritance.” [Design Patterns, pg. 20] Composition is: More flexible than inheritance Leads to lower coupling than inheritance Allows control over which delegate features are exposed, and what the API looks like
Background image of page 6
7 Choosing between Composition and Inheritance Inheritance: Supports polymorphism, while composition does not Is easier if you want to expose many of the superclass’ features Although Eclipse has a handy “Generate Delegate Methods” option for exposing delegate features if you’re using composition
Background image of page 7

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

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

Page1 / 29

Inheritance - Computer Science 340...

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

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