mercredi 22 mai 2019

Extending, Abstraction, Interfaces... Method Relationships between Classes designed for Scale

Curious as to someones opinion who's been through this rather steep curve in that of proper OOP design principles, into more advanced techniques of class relationships -- class inheritance, abstract classes, interfaces, traits, so on.

Me? First OOP project. Learning as I go. I've refactored, switched around, completely remodified my methods more time than I care to remember. Painful yet rewarding at the same time. Okay, enough of an intro, let's get into the meat of where I'm at.

PROJECT GOAL

Using chained curl responses to return the HTML of the requested page, pass that on to a DOM Class Handler which handles the parsing and extracting of sought information. This parsed information is then loaded into a DatabaseClass, which uses the information retrieved from the DOM parsing requests to appropriately store the data into the appropriate Database tables QL database.

I've only 3 Classes. Brief description immediately below each Class.

Class CurlHandler     {
//Methods to download data and images using cURL

Class DOMHandler      {
//Methods to parse the DOM from the cURL Results

Class DatabaseHandler {
// Methods to insert into a Database particular Data received from the DOM 

Here's the list of methods used in the class. I designed it as, for good or ill) an interface, providing for a more compact type for those with constantly changing the Dynamics

interface DOMInterface
{
    public function getNotice(\DiDom\Document $document): int;
    public function getStock(\DiDom\Document $document): int;
    public function getUPC(\DiDom\Document $xpath): int;
    public function getTitle(\DiDom\Document $document): int;
    public function getCurrentPrice(\DiDom\Document $document): int;
    public function getMSRP(\DiDom\Document $document): int;
    public function getPriceDiscount(\DiDom\Document $document): int;
    public function getImages(\DiDom\Document $document): int;
    public function getAttributes(\DiDom\Document $document): int;
    public function getTags(\DiDom\Document $document): int;
    public function getAttributes(\DiDom\Document $document): int;
    public function getLink(\DiDom\Document $document): int;
    public function pageCheck(int $page, int $pagelength): int;
}

And below are the ones I left out in the Interface, as these functions are more or less as is, static and designed to work in universal applications..

class DOMController implements DOMInterface 
{
public function setup (string $html);
public function write (string $file, string $producturl);
public function writeJSON (array $json, string $proxy, string $dir)
public function writeHTML (string $html, string $proxy,  string $dir)
}

As I stated earlier, aside from the obious reasions, one of the main reasons I get this down is crucial is scalability. As this project resolves around the parsing of different datasources and websites, my Classes must be conformed in a way that another website (Class) can easily be added and organized in an affluent way.

My other Classes are similar. I feel this post has reached close to it's maxim so I'll conclude, the similiarty between universal and specific are logical seperators that I've found, there's bound to be something I'm unaware of.

Tips, comments, why I'm wrong, how to be right.. I'd appreciate it. It's been a tough ride getting to this point.

Aucun commentaire:

Enregistrer un commentaire