What is the standard way to organize the contents of Java packages - in particular, the layout of interfaces and abstract classes

I guess this can go into many OO languages. I build my domain objects and don’t know where the best place is for interfaces and abstract classes.

If I have a pet pack with different implementations of the abstract APet class: should it live side by side with them or in the parent pack?

What about interfaces? It seems that they should almost live above the parent package implementations, since there may potentially be other subpackages that implement it, although there seems to be a stronger correlation between one abstract class and the subpackage.

eg.

com.foo
com.foo.IConsumer (interface)
com.foo.APet (abstract)
com.foo.pets.Dog extends APet implements IConsumer

OR

com.foo
com.foo.IConsumer (interface)
com.foo.pets.APet (abstract)
com.foo.pets.Dog extends APet implements IConsumer

or something else?

+3
3

. , factory. , , .

, - .

+3

, ( , ) , final , - ". Impl". , Pets Bird, Fish, Mammal Reptile , , , . Pets.Impl Goldfish, Canary, Collie, . , Bird , , , , .:)

0

, . , , ​​ . :

com.foo.APet (Abstract Class)
com.foo.pets.ADog extends com.foo.APet (Also Abstract)
com.foo.pets.impl.Westie extends ADog (not abstract).

In this case, the APet is at the top because it provides features common to all pets. ADog is definitely a pet, but it contains those things that are common to all DOGS. Classes in the impl package are manufactured using factory or whatever, and specialize in breed-based.

0
source

Source: https://habr.com/ru/post/1749637/


All Articles