开发者

create more object is inconsistent ? [closed]

开发者 https://www.devze.com 2022-12-15 19:25 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 9 years ago.

My question may be stupid, but i want to clear my doubt.

I am php, mysql developer.

While coding one of table requires objects from class A for each row.

Say it will create no of objects based on of row开发者_JAVA技巧.

Is this concept is inconsistent ?

Class A
{

    function __construct($userid)
    {

    }
}

class B
{
    function action_add($userid)
    {

    }
}

Therefore Class A needs to create each object for every row of table.

Class B require one object for a table.

Question 1

Using class A (many objects) is inconsistent ?

Question 2

In two classes which is best?


Sorry, I don't understand the context of the question and not sure what you mean by 'inconsistent'. But, these links might help:

Table Data Gateway architectural pattern http://martinfowler.com/eaaCatalog/tableDataGateway.html "An object that acts as a Gateway (466) to a database table. One instance handles all the rows in the table."

Data Mapper architectural pattern http://martinfowler.com/eaaCatalog/dataMapper.html "A layer of Mappers (473) that moves data between objects and a database while keeping them independent of each other and the mapper itself."

Perhaps you need both? One that has access to the entire table and one that represents a row from the table?

Extra stuff: Class B would suffice. But, if you want an extra level of indirection you might want both, one of which is a Data Mapper and one which is a Table Gateway (and have a 3rd class that represents your domain object e.g. a Person). Of course that might be an overkill, but it separates the domain object from the database details.

0

精彩评论

暂无评论...
验证码 换一张
取 消