The current design is
SharedFolder
is a subclass of Folder
.SharedFile
is a subclass of File
with a remote resource URL.Folder
accepts File
in an add
method.SharedFolder
accepts only SharedFile
but not non-shared File
File
can be moved to another Folder
with add
.SharedFolder
and Folder
is mostly the same.The add
in SharedFile
violate LSP. How to re-organize the object structure while allowing some UI code reuse?
You can genericize Folder
as Folder<T extends File>
, with add(T)
, and have SharedFolder extends Folder<SharedFile>
.
This way, SharedFolder
is only expected to substitute another Folder<SharedFile>
, but not any other type of Folder<File>
(If your language allows it. This would be possible in Java)