Structuring project (refactoring) [closed]

I’m working on a project that requires from me to make modular and extendible code structure. This code should be able to support multiple clients. The good news is that code should not do anything spectacular. I will explain this in more details later in the question.

So now I have around 30 branches for about 60 clients. Some clients needed their own branch because at the time it was easier to just separate their code from everyone else’s so that over time grow to 30 separated codes, that are very very similar.

So now architecture could not be more simpler. Request comes from client in XML form and then I process I return XML. Process part is mostly CRUD. Nothing fancy. I have two front controllers one for actions (INSERT, UPDATE, DELETE) and one for requests(SELECT). Then that front controller just includes script that client requested. Every request and every action has their own dedicated script. There are not a single class in the project. Everything is written in procedural way.

So in the new App structure the goal is to have one main branch that will all clients use and it will be managed from conf file.

I’m telling you all this because I’m not sure how to structure everything. I don’t have much experience with OOP I know the concepts and theory but its harder when it comes to actual coding in that style.

My idea now is. I’m leaving two front controller for action and request because that doesn’t require any change from client-side of application and that is important for now. They will now serve as only get request and echo it back. They will also call ActionController and RequestController. They will be a little smarter. They will know how to recognize which request/action client sent and then they will make new object of that class.

Every action/request has some steps that it needs to do. So i’m thinking that every class need some public method ‘execute’ that will just call method of that class by the order that it needs to, but I’m afraid that, that is also procedural way of thinking just it wont be in global score but in Class.

$client_request = new $fullClassPath(new $mapperClassPath);
$response = $client_request->execute($request);

Also How to handle Database, I probably should make actions on database as abstract as possible.

Configuration file will be very important, so I don’t know if it’s the solution to make class for every feature and include classes if that feature field is set to true in config file?

Every action has its own response to client and it can be pretty heavy xml. What is the solution there. Should I have a Response class that will handle that. Im afraid that the class will be pretty heavy because there are around 20 actions and 5 requests and everyone have different xml response.

So every help is appreciated with someone who had experience with similar projects, some links on good articles also wouldn’t hurt.

I should mention that language I’m working with is vanilla(plain) PHP.

It sounds like essentially the problem is that you have 30 processes which are similar but vary in inconsistent ways and you want to avoid duplicating code as much as possible while still being able to change any aspect if required.

In that case then the template method pattern can be very useful.

The basic idea is that you’d implement a base/abstract class which more or less functions in the most common way, then for each customer you create a child class which only overrides the methods which need to be changed.

For example:

abstract class BaseCustomer {

    protected $someValue = 5;

    protected function someProcess() {
        return $this->someValue * 2;
    }

    public function execute() {
        return $this->someProcess();
    }

}

class FirstCustomer extends BaseCustomer {
    protected $someValue = 10;
}

class SecondCustomer extends BaseCustomer {
    protected function someProcess() {
        return $this->someValue + 2;
    }
}

Calling ->execute() will return 20 for FirstCustomer and 7 for SecondCustomer.

A further step you can take is to use composition in combination with a template pattern to separate different components of your modules.

For example let’s say you have processes which send a CSV file in 5 different formats via either email, FTP or HTTP depending on the customer. You can have two sets of modules: one for the file format and one for the transport method.

Then go something like:

$format = new CustomerOneCSVFormat($data);
$transport = new FTPModule();
$transport->send($format);

In that example you could support 15 different combinations from only 8 classes (plus the base/abstract class).

When designing your base class it’s important to keep in the internal functions short and divided along the lines of what you’re likely to change on a customer-by-customer basis, that will avoid having to copy large chunks of code to child classes just to change a few lines.

It’s hard to say how to structure your application without knowing the differences between each ‘branch’. What I would do is compare the functionality of each branch and distill the common denominators. Put these into classes that you use for each client. The parts that differ from client to client I would then put into adapters or strategies that (optimally) share a common interface.

We had the same problem with a codebase I inherited. Some pointers I used in that project:

  • Heavy use of adapters or strategies.
  • Use of dependency injection to swap out different classes for different clients.
  • If a client needs a special exception, see if it can instead be added to the generic classes using some configuration.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Structuring project (refactoring) [closed]

I’m working on a project that requires from me to make modular and extendible code structure. This code should be able to support multiple clients. The good news is that code should not do anything spectacular. I will explain this in more details later in the question.

So now I have around 30 branches for about 60 clients. Some clients needed their own branch because at the time it was easier to just separate their code from everyone else’s so that over time grow to 30 separated codes, that are very very similar.

So now architecture could not be more simpler. Request comes from client in XML form and then I process I return XML. Process part is mostly CRUD. Nothing fancy. I have two front controllers one for actions (INSERT, UPDATE, DELETE) and one for requests(SELECT). Then that front controller just includes script that client requested. Every request and every action has their own dedicated script. There are not a single class in the project. Everything is written in procedural way.

So in the new App structure the goal is to have one main branch that will all clients use and it will be managed from conf file.

I’m telling you all this because I’m not sure how to structure everything. I don’t have much experience with OOP I know the concepts and theory but its harder when it comes to actual coding in that style.

My idea now is. I’m leaving two front controller for action and request because that doesn’t require any change from client-side of application and that is important for now. They will now serve as only get request and echo it back. They will also call ActionController and RequestController. They will be a little smarter. They will know how to recognize which request/action client sent and then they will make new object of that class.

Every action/request has some steps that it needs to do. So i’m thinking that every class need some public method ‘execute’ that will just call method of that class by the order that it needs to, but I’m afraid that, that is also procedural way of thinking just it wont be in global score but in Class.

$client_request = new $fullClassPath(new $mapperClassPath);
$response = $client_request->execute($request);

Also How to handle Database, I probably should make actions on database as abstract as possible.

Configuration file will be very important, so I don’t know if it’s the solution to make class for every feature and include classes if that feature field is set to true in config file?

Every action has its own response to client and it can be pretty heavy xml. What is the solution there. Should I have a Response class that will handle that. Im afraid that the class will be pretty heavy because there are around 20 actions and 5 requests and everyone have different xml response.

So every help is appreciated with someone who had experience with similar projects, some links on good articles also wouldn’t hurt.

I should mention that language I’m working with is vanilla(plain) PHP.

It sounds like essentially the problem is that you have 30 processes which are similar but vary in inconsistent ways and you want to avoid duplicating code as much as possible while still being able to change any aspect if required.

In that case then the template method pattern can be very useful.

The basic idea is that you’d implement a base/abstract class which more or less functions in the most common way, then for each customer you create a child class which only overrides the methods which need to be changed.

For example:

abstract class BaseCustomer {

    protected $someValue = 5;

    protected function someProcess() {
        return $this->someValue * 2;
    }

    public function execute() {
        return $this->someProcess();
    }

}

class FirstCustomer extends BaseCustomer {
    protected $someValue = 10;
}

class SecondCustomer extends BaseCustomer {
    protected function someProcess() {
        return $this->someValue + 2;
    }
}

Calling ->execute() will return 20 for FirstCustomer and 7 for SecondCustomer.

A further step you can take is to use composition in combination with a template pattern to separate different components of your modules.

For example let’s say you have processes which send a CSV file in 5 different formats via either email, FTP or HTTP depending on the customer. You can have two sets of modules: one for the file format and one for the transport method.

Then go something like:

$format = new CustomerOneCSVFormat($data);
$transport = new FTPModule();
$transport->send($format);

In that example you could support 15 different combinations from only 8 classes (plus the base/abstract class).

When designing your base class it’s important to keep in the internal functions short and divided along the lines of what you’re likely to change on a customer-by-customer basis, that will avoid having to copy large chunks of code to child classes just to change a few lines.

It’s hard to say how to structure your application without knowing the differences between each ‘branch’. What I would do is compare the functionality of each branch and distill the common denominators. Put these into classes that you use for each client. The parts that differ from client to client I would then put into adapters or strategies that (optimally) share a common interface.

We had the same problem with a codebase I inherited. Some pointers I used in that project:

  • Heavy use of adapters or strategies.
  • Use of dependency injection to swap out different classes for different clients.
  • If a client needs a special exception, see if it can instead be added to the generic classes using some configuration.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Structuring project (refactoring) [closed]

I’m working on a project that requires from me to make modular and extendible code structure. This code should be able to support multiple clients. The good news is that code should not do anything spectacular. I will explain this in more details later in the question.

So now I have around 30 branches for about 60 clients. Some clients needed their own branch because at the time it was easier to just separate their code from everyone else’s so that over time grow to 30 separated codes, that are very very similar.

So now architecture could not be more simpler. Request comes from client in XML form and then I process I return XML. Process part is mostly CRUD. Nothing fancy. I have two front controllers one for actions (INSERT, UPDATE, DELETE) and one for requests(SELECT). Then that front controller just includes script that client requested. Every request and every action has their own dedicated script. There are not a single class in the project. Everything is written in procedural way.

So in the new App structure the goal is to have one main branch that will all clients use and it will be managed from conf file.

I’m telling you all this because I’m not sure how to structure everything. I don’t have much experience with OOP I know the concepts and theory but its harder when it comes to actual coding in that style.

My idea now is. I’m leaving two front controller for action and request because that doesn’t require any change from client-side of application and that is important for now. They will now serve as only get request and echo it back. They will also call ActionController and RequestController. They will be a little smarter. They will know how to recognize which request/action client sent and then they will make new object of that class.

Every action/request has some steps that it needs to do. So i’m thinking that every class need some public method ‘execute’ that will just call method of that class by the order that it needs to, but I’m afraid that, that is also procedural way of thinking just it wont be in global score but in Class.

$client_request = new $fullClassPath(new $mapperClassPath);
$response = $client_request->execute($request);

Also How to handle Database, I probably should make actions on database as abstract as possible.

Configuration file will be very important, so I don’t know if it’s the solution to make class for every feature and include classes if that feature field is set to true in config file?

Every action has its own response to client and it can be pretty heavy xml. What is the solution there. Should I have a Response class that will handle that. Im afraid that the class will be pretty heavy because there are around 20 actions and 5 requests and everyone have different xml response.

So every help is appreciated with someone who had experience with similar projects, some links on good articles also wouldn’t hurt.

I should mention that language I’m working with is vanilla(plain) PHP.

It sounds like essentially the problem is that you have 30 processes which are similar but vary in inconsistent ways and you want to avoid duplicating code as much as possible while still being able to change any aspect if required.

In that case then the template method pattern can be very useful.

The basic idea is that you’d implement a base/abstract class which more or less functions in the most common way, then for each customer you create a child class which only overrides the methods which need to be changed.

For example:

abstract class BaseCustomer {

    protected $someValue = 5;

    protected function someProcess() {
        return $this->someValue * 2;
    }

    public function execute() {
        return $this->someProcess();
    }

}

class FirstCustomer extends BaseCustomer {
    protected $someValue = 10;
}

class SecondCustomer extends BaseCustomer {
    protected function someProcess() {
        return $this->someValue + 2;
    }
}

Calling ->execute() will return 20 for FirstCustomer and 7 for SecondCustomer.

A further step you can take is to use composition in combination with a template pattern to separate different components of your modules.

For example let’s say you have processes which send a CSV file in 5 different formats via either email, FTP or HTTP depending on the customer. You can have two sets of modules: one for the file format and one for the transport method.

Then go something like:

$format = new CustomerOneCSVFormat($data);
$transport = new FTPModule();
$transport->send($format);

In that example you could support 15 different combinations from only 8 classes (plus the base/abstract class).

When designing your base class it’s important to keep in the internal functions short and divided along the lines of what you’re likely to change on a customer-by-customer basis, that will avoid having to copy large chunks of code to child classes just to change a few lines.

It’s hard to say how to structure your application without knowing the differences between each ‘branch’. What I would do is compare the functionality of each branch and distill the common denominators. Put these into classes that you use for each client. The parts that differ from client to client I would then put into adapters or strategies that (optimally) share a common interface.

We had the same problem with a codebase I inherited. Some pointers I used in that project:

  • Heavy use of adapters or strategies.
  • Use of dependency injection to swap out different classes for different clients.
  • If a client needs a special exception, see if it can instead be added to the generic classes using some configuration.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật