Need clarification of what is this Public API in J

2019-05-10 03:45发布

I heart a lot about the term Public API from JavaFX speakers.

  • What is Public API supposed to mean ?
  • Conversely, is there a Private API ?

3条回答
成全新的幸福
2楼-- · 2019-05-10 04:29

All classes in javafx-namespace are the public API and you won't get broken in future releases of JavaFX, classes found in com.sun.javafx in contrast are private and can change from release to release

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-05-10 04:30

Public API is not a JavaFX term.

It is a term that applies to Java programs generally.

The Public API of a program is all of the following found in all its public classes:

  • fields of classes that are not private and not package-private
  • interfaces that are not package-private
  • methods that are not private and not package-private
  • member classes that are not private and not package-private

A synonym for Public API is "exported API". These are the features of your application that become accessible to other programmers who want to use your application in their own development.

The "private API" is simply those other features of your program that are not covered by the above. These private memebers of your classes are your "implementation details" and you are free to change or edit them as much as you wish as long as such changes do not impact the public API.

The ability to distinguish the implementation details from the exported API is an important concept in object-oriented programming in general and of Java programming in particular. This ability is often referred to as "encapsulation".

查看更多
三岁会撩人
4楼-- · 2019-05-10 04:38

The most important things, you should understand about private and public API:

At first, technicly, you can use both of them.

At the second. when developers develop some programs, they think - this is for users, and this is our implementation. And when time goes, programs can change. And when developers add changes - if it is a change about private API - they do everything they want, just passing internal code review process. But, when appears a need to change a public API - they start to think. If it is really needed, and no other solution can be done, they change public API, and provide all info about the change (release notes for instance).

It is common process - to think previously, and develop separation between public and private APIs, so that user can have stable API of product functionality.

At the third : about JavaFX : its private APIs are living. Product is under development, and these APIs are changing rapidly. Public APIs, are mostly stable, and the most common thing about public API change - when class publicly available methods are added (new functionality).

If you want/need to use some functionality from private API - it is your risk. It can be changed, or even removed. Developers side is not under responsibility to keep private functionality in the product, or with stable API.

Finally, you can file an RFE in javafx-jira, to request making its functionality publicly available. And if it really nice idea (decided by developers; may be after public discussion; making attention on voting results) - it could be done.

查看更多
登录 后发表回答