INTRODUCTION TO INHERITANCE Mimi Opkins CECS 277 An

  • Slides: 13
Download presentation
INTRODUCTION TO INHERITANCE Mimi Opkins CECS 277

INTRODUCTION TO INHERITANCE Mimi Opkins CECS 277

An Anology Let’s look at an analogy between the work of an architect and

An Anology Let’s look at an analogy between the work of an architect and the work of a programmer. The way that an architect handles the complexity of a large building design sheds some light on how we can organize our own programming work. This analogy lets us consider the same concepts but without the distraction of Java syntax and semantics.

Basics The architect begins by considering the overall requirements for a building: square footage,

Basics The architect begins by considering the overall requirements for a building: square footage, number of occupants, types of usage, size of the building lot, height limits, and so on. After making some initial decisions, the architect faces a basic aspect of any design: The building is composed of floors. In many buildings, the floors all have common characteristics: the same size and shape; the same number and locations for elevator shafts, stairways, and utility trunks; and so on. The architect could begin by designing a basic empty floor with all of these common elements in place. Once she installs this plan in the library of her computer aided design (CAD) program, she can then use it repeatedly as the starting point for designing each floor of the building.

Basic Empty Floor

Basic Empty Floor

Types of Objects The architect may further decide that the building has two main

Types of Objects The architect may further decide that the building has two main types of floors: office floors and mechanical equipment floors. The office floors might be of two types: executive office space and standard office space. Starting from the basic empty floor design, the architect adds components such as lavatories and hallways to make an empty office floor. She can then add offices and conference rooms to the empty space. Each of the four types of floor is thus derived from the basic empty floor and added to the library. Drawing the entire building then becomes simply a matter of creating an instance of one of these four floor plans for each story.

Mechanical Floor

Mechanical Floor

Empty Office Floor

Empty Office Floor

Designing Components The architect uses the same process to design the components that make

Designing Components The architect uses the same process to design the components that make up the floors. She might design a basic type of office, with a door, windows, lights, heating, wiring, and so forth, and then derive several types of offices from that one design. From a given type of office, such as secretarial, she might further refine the design into subtypes such as general secretarial, secretary/receptionist, and executive secretary.

Inheriting (Hierarchy of Design) Creating hierarchies of designs simplifies the architect’s job. She begins

Inheriting (Hierarchy of Design) Creating hierarchies of designs simplifies the architect’s job. She begins each hierarchy with the most general form of a building component, such as the basic empty floor, and then derives new designs by adding details to the more general forms. The new designs inherit all of the characteristics of the general form, saving the architect from having to redraw those pieces they share in common.

Floor Hierarchy

Floor Hierarchy

Overriding In some cases she replaces existing parts of a design, as when she

Overriding In some cases she replaces existing parts of a design, as when she substitutes a wider door for a reception area than appears in the basic secretarial office. The replacement part overrides what was originally specified in the more general form. In addition to the components of individual floors, the architect can specify characteristics that are common to all floors, such as a color scheme. Each floor will then inherit these general properties.

Executive Office Floor

Executive Office Floor

Standard Office Floor

Standard Office Floor