10OOPDesign1

10OOPDesign1 - CS108 Stanford Winter 2010 Handout#10 Young...

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

View Full Document Right Arrow Icon
CS108, Stanford Handout #10 Winter 2010 Young OOP Design Handout written by Nick Parlante OOP Design OOP Design spans a few main themes. .. - Encapsulation and modularity - API/Client interface design - Inheritance hierarchy and interfaces Here we concentrate on OOP encapsulation and API/interface design. Note that this is more than one lecture's worth of material. Software Engineering Crisis -- Systems -- Modularity Problem -- building large systems made up of complex parts, hit "n squared" limit Picture of typical project -- many complex parts Code of one part can interfere with code of another Solution -- modularity. Keep components as separate and independent from each other as possible. This idea works in many coding styles, but is embodied in OOP especially well. Self taught people can fall into the trap of building the system as one large thing. Experience with very large projects shows the value of deliberate modularity -- building the large thing out of consciously modular parts. OOP Design -- Encapsulation Divide the code for a project up around its nouns. Create a class for each type of noun -- storing the data for that type of noun and the operations that work on it. "Encapsulation" is the idea of housing data in an object which stores and manages that data, exposing a clean interface for use by clients while keeping implementation details hidden. Each class exposes public methods for use by other "client" classes. - Expose operations in a way which is most convenient for the clients - The data and implementation details are kept private inside the object as much as possible. e.g. An Address object is made of a String street address, a String country, . .. gather those components together to form the single coherent "Address" object. Interface vs. Implementation Implementation -- private, internal - How is the object implemented -- how does it organizes its data into instance variables. - Methods -- what data structures and code to do the actual implementation. - The word "detail" suggests some feature of issue of the implementation, but which the client does not need to know. It can be kept hidden inside the object -- great! When someone says "that's a detail", they mean it's not something the client cares about. Interface -- public API, external - How does the object "expose" its abilities as public methods for use by client classes. - The interface must expose just the issues that are needed and relevant to the computation -- keeping the implementation details hidden as much as possible. - The public interface/API should be organized for the convenience and needs of the clients. A great client interface may look quite different from the underlying implementation. The clients need never know this -- they never see or depend on the implementation details.
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 Asymmetry -- there is a basic asymmetry between the interface and implementation. With a good design, the interface is simple and minimal compared to the (complex, detailed) implementation that it
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/12/2010 for the course CS 108 taught by Professor Jimenez during the Winter '08 term at Stanford.

Page1 / 10

10OOPDesign1 - CS108 Stanford Winter 2010 Handout#10 Young...

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

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