Оцените презентацию от 1 до 5 баллов!
Тип файла:
ppt / pptx (powerpoint)
Всего слайдов:
8 слайдов
Для класса:
1,2,3,4,5,6,7,8,9,10,11
Размер файла:
42.76 kB
Просмотров:
82
Скачиваний:
0
Автор:
неизвестен
Слайды и текст к этой презентации:
№1 слайд![Item Prefer interfaces to](/documents_6/9086edc5a82e675c7dd81d6b91a8aa3c/img0.jpg)
Содержание слайда: Item 18: Prefer interfaces to abstract classes
№2 слайд![Existing classes can be](/documents_6/9086edc5a82e675c7dd81d6b91a8aa3c/img1.jpg)
Содержание слайда: Existing classes can be easily redesigned to implement a new interface
Steps to add a new interface for several classes:
add an “implements interfaceName” in each class
add the required methods for each class
What about abstract classes?
Two classes should extend the same abstract class –>
Place the abstract class high up in the type hierarchy after an ancestor of both classes –>
Great damage to the type hierarchy.
№3 слайд![Interfaces are ideal for](/documents_6/9086edc5a82e675c7dd81d6b91a8aa3c/img2.jpg)
Содержание слайда: Interfaces are ideal for defining mixins.
Mixins provides some additional behavior
(For example Comparable)
Class can implement several mixins as interfaces
Class can have only one superclass –
there is no place in hierarchy for mixins as abstract classes
№4 слайд![Interfaces allow the](/documents_6/9086edc5a82e675c7dd81d6b91a8aa3c/img3.jpg)
Содержание слайда: Interfaces allow the construction of nonhierarchical types
interface Singer
+ interface Songwriter
= interface SingerSongwriter extends Singer, Songwriter
The alternative is a bloated class hierarchy containing a separate class for every supported combination of attributes
(2n possible combinations).
№5 слайд![Interfaces enable safe and](/documents_6/9086edc5a82e675c7dd81d6b91a8aa3c/img4.jpg)
Содержание слайда: Interfaces enable safe and powerful
increasing of functionality
+ Using an interface – enable to use composition
- Using an abstract class – no alternative but to use inheritance
№6 слайд![Abstract skeletal](/documents_6/9086edc5a82e675c7dd81d6b91a8aa3c/img5.jpg)
Содержание слайда: Abstract skeletal implementation class
Combination:
Skeletal implementation = Interface + Abstract class
Skeletal implementations are called AbstractInterface
(AbstractCollection, AbstractSet, AbstractList, AbstractMap)
Simulated multiple inheritance
Simple implementation
№7 слайд![Advantage of abstract classes](/documents_6/9086edc5a82e675c7dd81d6b91a8aa3c/img6.jpg)
Содержание слайда: Advantage of abstract classes:
It is far easier to evolve an abstract class
than an interface
+ All existing implementations of the abstract class will then provide the new method
- Once an interface is released and implemented,
it is almost impossible to change
№8 слайд![Item Use interfaces only to](/documents_6/9086edc5a82e675c7dd81d6b91a8aa3c/img7.jpg)
Содержание слайда: Item 19: Use interfaces only to define types
Don’t use constant interfaces, it’s antipattern.
Use utility classes for constants and static import.
Constant interfaces in the Java platform libraries, such as java.io.ObjectStreamConstants - should be regarded as anomalies