Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Ganesh_JavaSE7_Programming_1z0-804_study_guide.pdf
Скачиваний:
94
Добавлен:
02.02.2015
Размер:
5.88 Mб
Скачать

Chapter 5

Object-Oriented Design Principles

 

Write code that declares, implements and/or extends interfaces

 

Choose between interface inheritance and class inheritance

 

Develop code that implements "is-a" and/or "has-a" relationships.

Exam Topics

Apply object composition principles

 

Design a class using the Singleton design pattern

 

Write code to implement the DAO pattern

 

Design and create objects using a factory, and use factories from the API

We covered object-oriented programming basics in Chapter 3 and more advanced OOP topics in Chapter 4. In this chapter, we delve still more deeply into OOP concepts.

The chapter begins with an in-depth investigation of interfaces. We will discuss how interfaces are different from abstract classes and which construct to use in a given situation. In the second section, we introduce you to the object composition principle that says “favor composition over inheritance.” The third and fourth sections cover one of most popular topics in OOP: design patterns. You will learn the basic concepts behind design patterns and how they relate to OOP. We’ll focus on the singleton, factory, abstract factory, and data access object (DAO) design patterns.

Interfaces

In general, an interface refers to a common boundary or interconnection between two entities (which could be human beings, systems, concepts, machines, etc.). For instance, a keyboard in a computer system provides an interface between a human being and the computer. A natural language such as English is an interface between two humans that allows them to exchange their views.

In Java, an interface is a set of abstract methods that defines a protocol (i.e., a contract for conduct). Classes that implement an interface must implement the methods specified in the interface. An interface defines a protocol, and a class implementing the interface honors the protocol. In other words, an interface promises a certain functionality

113

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]