[
https://issues.apache.org/jira/browse/HDFS-8499?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14632040#comment-14632040
]
Tsz Wo Nicholas Sze commented on HDFS-8499:
-------------------------------------------
Each Java class can implement multiple interfaces but extend to only one class.
We should choose the one with the strongest is-a relationship for extending.
In our case, we have the following desirable is-a relationships.
- *(A)* BlockInfoUC is-a BlockInfo.
- *(B)* BlockInfoContiguousUC is-a BlockInfoContiguous and BlockInfoStripedUC
is-a BlockInfoStriped.
The design #1 in [this
comment|https://issues.apache.org/jira/browse/HDFS-8499?focusedCommentId=14578064&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14578064]
chooses (A) over (B). From the diagram below, a
BlockInfoContiguousUC/BlockInfoStripedUC is not a
BlockInfoContiguous/BlockInfoStriped. It seems incorrect. We cannot cast a
BlockInfoContiguousUC/BlockInfoStripedUC object to
BlockInfoContiguous/BlockInfoStriped.
{code}
// Design #1
BlockInfo (abstract)
/ | \
BlockInfoStriped | BlockInfoContiguous
|
BlockInfoUC(abstract)
/ \
BlockInfoStripedUC BlockInfoContiguousUC
{code}
We may remedy it by adding interfaces as above. However, the is-a relationship
becomes more complicated.
{code}
// Design #1'
BlockInfo(abstract)
/ | \
/ | \
BlockInfoStripedInterface / | \
BlockInfoContiguousInterface
| \ / | \ / |
| BlockInfoStriped | BlockInfoContiguous |
| | |
| BlockInfoUC(abstract) |
| / \ |
BlockInfoStripedUC BlockInfoContiguousUC
{code}
For the second design, BlockInfoStripedUC is-a BlockInfo, BlockInfoUC and
BlockInfoStriped at the same time. The only drawback is that a BlockInfoUC is
not a BlockInfo. It is fine since BlockInfoUC is only an interface -- the
implementation classes always is-a BlockInfo by the disgram below. We always
can safely cast a BlockInfoUC object to BlockInfo.
{code}
// Design #2
BlockInfo (abstract)
/ \
BlockInfoStriped BlockInfoContiguous
| |
| BlockInfoUC |
| (interface) |
| / \ |
BlockInfoStripedUC BlockInfoContiguousUC
{code}
> Refactor BlockInfo class hierarchy with static helper class
> -----------------------------------------------------------
>
> Key: HDFS-8499
> URL: https://issues.apache.org/jira/browse/HDFS-8499
> Project: Hadoop HDFS
> Issue Type: Sub-task
> Components: namenode
> Affects Versions: 2.7.0
> Reporter: Zhe Zhang
> Assignee: Zhe Zhang
> Fix For: 2.8.0
>
> Attachments: HDFS-8499.00.patch, HDFS-8499.01.patch,
> HDFS-8499.02.patch, HDFS-8499.03.patch, HDFS-8499.04.patch,
> HDFS-8499.05.patch, HDFS-8499.06.patch, HDFS-8499.07.patch,
> HDFS-8499.UCFeature.patch, HDFS-bistriped.patch
>
>
> In HDFS-7285 branch, the {{BlockInfoUnderConstruction}} interface provides a
> common abstraction for striped and contiguous UC blocks. This JIRA aims to
> merge it to trunk.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)