How to present the required business fields in the model structure?

If we use a type hint, we can put the object mandatory:

public function myMethodThatDoFineStuff(MyObject $myobject) {

}

What if we want to place, not the entire object, but only some of its attributes, necessary? Suppose our domain model is better if it better represents a specific domain. If this can make more sense in our business model (in our domain)? How do we do this?

We should always place an ALL-object no matter what?


An EXAMPLE for explanation suggests:

Suppose that in order to list the books of a certain author, we have this method:

public function listBookOfAuthor(Author $author) {

}

, - 200 , , first .

ALL $author?

+5
3

:

public function listBookOfAuthor(Author $author) {

    if (empty($author->firstName)) {
        throw new listBookOfAuthorException('firstName must be defined');
    }

}

, , - , .

+2

, , ?

, . , , PHP.

, -?

-, , . , , .

ALL , ?

, . , . , ( ), stclass. stdclass , , .

+2

listBooksOfAuthor() ( , BookService), , $authorId, Author .

, . , Author - , , AuthorService::getAuthorById().

, , - Author, , - , - AuthorSummaryInterface - , . Author , , Author, , Author. , Author:getSummary(), AuthorSummaryInterface. - , exmaple - , .

You can also create a set of methods — perhaps on the object AuthorServiceor object AuthorSummaryServicethat creates the objects AuthorSummary. Then, in cases where only AuthorSummaryInterfacefunctionality is required , you can create these limited functionality, less expensive objects.

Just some ideas.

+2
source

All Articles