java - Will inheritance break encapsulation? -
let's have csv file , create class called csvfile
extends java.io.file
. class can parse csv file , return data how many columns in file. can used functions takes java.io.file
input. fileutils.copyfile(file from, file to)
.
my colleague thinks expose inheritance. idea wrap java.io.file
holding in private property, instead of inheriting it. think exposing public method/property file breaks encapsulation, take benefit since functions in java.io.file
free.
what think?
i rather agree colleague: inheriting java.util.file
expose methods not applicable csvfile
objects, such list()
, listfiles()
, setexecutable()
, , on.
making java.util.file
property behind getter sounds better choice: not reveal irrelevant operations users of class, , lets inherit base class of choice.
Comments
Post a Comment