1) An abstract method is a method that is incomplete. It has only a declaration and no method body. Here is the syntax for an abstract method declaration: abstract void f();
2) A class containing abstract methods is called an abstract class. If a class contains one or more abstract methods, the class itself must be qualified as abstract.
3) If you inherit from an abstract class and you want to make objects of the new type, you must provide method definitions for all the abstract methods in the base class. If you don’t (and you may choose not to), then the derived class is also abstract, and the compiler will force you to qualify that class with the abstract keyword.
4) It’s possible to make a class abstract without including any abstract methods. This is useful when you’ve got a class in which it doesn’t make sense to have any abstract methods, and yet you want to prevent any instances of that class.
5) The interface keyword produces a completely abstract class, one that provides no implementation at all. It allows the creator to determine method names, argument lists, and return types, but no method bodies. An interface provides only a form, but no implementation.
6) An interface is more than just an abstract class taken to the extreme, since it allows you to perform a variation of "multiple inheritance" by creating a class that can be upcast to more than one base type.
7) To create an interface, use the interface keyword instead of the class keyword. An interface can also contain fields, but these are implicitly static and final.
8) To make a class that conforms to a particular interface (or group of interfaces), use the implements keyword, which says, "The interface is what it looks like, but now I’m going to say how it works." Other than that, it looks like inheritance.
9) You can choose to explicitly declare the methods in an interface as public, but they are public even if you don’t say it. So when you implement an interface, the methods from the interface must be defined as public.
10) Java compiler dosen't allow you to reduce the accessibility of a method during inheritance.
11) The split( ) method is part of the String class. It takes the String object and splits it using the argument as a boundary, and returns a String[ ].
12) Creating a method that behaves differently depending on the argument object that you pass it is called the Strategy design pattern.
13) You are often in the situation of not being able to modify the classes that you want to use. For example, the library was discovered rather than created. In these cases, you can use the Adapter design pattern. In Adapter, you write code to take the interface that you have and produce the interface that you need. ( usually using delegation )
14) If you do inherit from a non-interface, you can inherit from only one. All the rest of the base elements must be interfaces. You place all the interface names after the implements keyword and separate them with commas. When you combine a concrete class with interfaces this way, the concrete class must come first, then the interfaces.
15) One of the core reasons for interfaces is: upcast to more than one base type (and the flexibility that this provides). However, a second reason for using interfaces is the same as using an abstract base class: to prevent the client programmer from making an object of this class and to establish that it is only an interface.
16) extends can refer to multiple base interfaces when building a new interface and the base interface names are simply separated with commas.
17) You cannot inherit from one base class and some interfaces that have the same funciton signature but with imcompatible return type.
18) A common use for interfaces is the Strategy design pattern. You write a method that performs certain operations, and that method takes an interface that you also specify. You’re basically saying, "You can use my method with any object you like, as long as your object conforms to my interface." This makes your method more flexible, general and reusable. A method that takes an interface provides a way for any class to be adapted to work with that method. This is the power of using interfaces instead of classes.
19) Because any fields you put into an interface are automatically public, static and final, the interface is a convenient tool for creating groups of constant values.
20) Fields defined in interfaces cannot be "blank finals", it even can't have any initializers (static or non-static ).
21) Interfaces may be nested within classes and within other interfaces. interface itself is implicitly static, so it cannot be defined in non-static inner class.
22) Just like non-nested interfaces, a nested interface in a class can have public or package-access visibility. And it can also be private, but this interface can only be accessed within its defining class.
23) Interfaces can be nested within each other. However, the rules about interfaces—in particular, that all interface elements must be public—are strictly enforced here, so an interface nested within another interface is automatically public and cannot be made private.
24) Factory Method design pattern: instead of calling a constructor directly, you call a creation method on a factory object which produces an implementation of the interface—this way, in theory, your code is completely isolated from the implementation of the interface, thus making it possible to transparently swap one implementation for another.
25) An appropriate guideline is to prefer classes to interfaces. Start with classes, and if it becomes clear that interfaces are necessary, then refactor.
相关推荐
Chapter 9. View Controllers Chapter 10. Putting It All Together Chapter 11. Designing for Test-Driven Development Chapter 12. Applying Test-Driven Development to an Existing Project Chapter 13. Beyond...
Chapter 9. Message Queues and Asynchronous Components Chapter 10. Databases Chapter 11. Simplifying Design with Dependency Injection Chapter 12. Working with Web Applications Chapter 13. Keeping Your ...
Early Realease Take your web development skills from...Chapter 9. Node and ES6 Chapter 10. Full-stack Node Development Chapter 11. Node in Development and Production Chapter 12. Node in New Environments
Part 1: Preparations Chapter 1. Orientation to Transport Networks ...Chapter 9. Mesh Network Topology Design and Evolution Chapter 10. p-Cycles Chapter 11. Ring-Mesh Hybrids and Ring-to-Mesh Evolution
-chapter9 线程局部存储 -HelloWorld.exe -chapter10 加载配置信息 -HelloWorld.exe -chapter11 动态加载技术 -HelloWorld.exe -chapter12 PE变形技术 -HelloWorld.exe -chapter13 PE补丁技术 -Hello...
Chapter 9. Detection and Estimation Chapter 10. Power Spectrum Density Estimation Chapter 11. Time-Frequency Analysis Chapter 12. Parametrical Time-Frequency Methods Chapter 13. Supervised Statistical...
Finding patterns in massive event streams can be difficult, but learning how to find them doesn’t have to be. This unique hands-on guide shows you how to solve ...Chapter 9. Duplicate and Unique Records
A design handbook to orchestrate and manage ...Chapter 9. Adaptive Case Management Chapter 10. Mobile and Multichannel Chapter 11. Event Processing and BPM Chapter 12. Business Activity Monitoring
mainly from the compiler options files (co-...lnt). For example options files co-msc70.lnt, co-msc71.lnt, co-msc80.lnt and co-msc90.lnt support versions 7.0, 7.1, 8.0 and 9.0 respectively. -----...
Written by a Linux expert and technology trainer, the book provides learning objectives at the beginning of each chapter, exam tips, practice exam questions, and in-depth answer explanations....
Chapter 9. Fine-tune task scheduling Chapter 10. Fine-tune task details Chapter 11. Fine-tune resource and assignment details Chapter 12. Fine-tune the Project plan Chapter 13. Organize plan details ...
Leverage the power of protocol-oriented programming in your applications and learn from real world use cases Create a flexible codebase with protocols and protocol extensions Increase the overall ...