1111use  Kmeans \Interfaces \PointCollectionInterface ;
1212use  Kmeans \Interfaces \PointInterface ;
1313
14- class  Algorithm implements  AlgorithmInterface
14+ abstract   class  Algorithm implements  AlgorithmInterface
1515{
1616    private  InitializationSchemeInterface   $ initScheme ;
1717
@@ -25,6 +25,10 @@ public function __construct(InitializationSchemeInterface $initScheme)
2525        $ this  ->initScheme  = $ initScheme ;
2626    }
2727
28+     abstract  protected  function  getDistanceBetween (PointInterface   $ pointA , PointInterface   $ pointB ): float ;
29+ 
30+     abstract  protected  function  findCentroid (PointCollectionInterface   $ points ): PointInterface  ;
31+ 
2832    public  function  registerIterationCallback (callable  $ callback ): void 
2933    {
3034        $ this  ->iterationCallbacks [] = $ callback ;
@@ -48,18 +52,6 @@ public function clusterize(PointCollectionInterface $points, int $nbClusters): C
4852        return  $ clusters ;
4953    }
5054
51-     protected  function  getDistanceBetween (PointInterface   $ pointA , PointInterface   $ pointB ): float 
52-     {
53-         return  Math::euclideanDist ($ pointA ->getCoordinates (), $ pointB ->getCoordinates ());
54-     }
55- 
56-     protected  function  findCentroid (PointCollectionInterface   $ points ): PointInterface 
57-     {
58-         return  new  Point ($ points ->getSpace (), Math::centroid (
59-             array_map (fn  (PointInterface   $ point ) => $ point ->getCoordinates (), iterator_to_array ($ points ))
60-         ));
61-     }
62- 
6355    private  function  iterate (ClusterCollectionInterface   $ clusters ): bool 
6456    {
6557        /** @var \SplObjectStorage<ClusterInterface, null> */ 
@@ -110,7 +102,7 @@ private function getClosestCluster(ClusterCollectionInterface $clusters, PointIn
110102        return  $ closest ;
111103    }
112104
113-     protected  function  invokeIterationCallbacks (ClusterCollectionInterface   $ clusters ): void 
105+     private  function  invokeIterationCallbacks (ClusterCollectionInterface   $ clusters ): void 
114106    {
115107        foreach  ($ this  ->iterationCallbacks  as  $ callback ) {
116108            $ callback ($ this  , $ clusters );
0 commit comments