Java - Abstract class to contain variables?

前端 未结 3 1547
Happy的楠姐
Happy的楠姐 2021-01-03 21:13

Is it good practice to let abstract classes define instance variables?

public abstract class ExternalScript extends Script {

    String source;

    public          


        
3条回答
  •  囚心锁ツ
    2021-01-03 21:35

    Sure.. Why not?
    Abstract base classes are just a convenience to house behavior and data common to 2 or more classes in a single place for efficiency of storage and maintenance. Its an implementation detail.
    Take care however that you are not using an abstract base class where you should be using an interface. Refer to Interface vs Base class

提交回复
热议问题