douyi1982 2016-08-11 12:27
浏览 46
已采纳

是正确的绑定具体实现?

I'm using Laravel 5.2 to build an abstract system. When a customer needs some specific implementation, I need to override some parts of the code.

What I'm thinking is something like this scenario:

A Controller depends on some custom Request (concrete) by default. When a customer asks me another business rule, I'd have to extend this custom Request and bind this child implementation to the parent. Do something like this on my Provider:

$this->app->bind(ParentImpl::class, ChildImpl::class);

Talking about software architecture concepts, can I do it? Is it correct?

[EDIT]

A concrete example, I have an action that uses a Request like this:

class SomeController extends Controller
{

   public function someAction(ParentRequest $request)
   {
       # perform action
   }

}

My Request have some business validation logic:

class ParentRequest extends Request
{

   public function rules()
   {
      return [
         'a_field' => 'required',
         'b_field' => 'max:100'
      ];
   }

}

Now everything works, my default system logic is ok! But my software is a base to other projects, we will use it via composer and at the final projects just the specific code will belong to app path.

When a customer ask for some modification of business logic we'll need to override the old. My question is: is it correct? Can I, conceptually talking, do something like this code below?

class ChildRequest extends ParentRequest
{

   public function rules()
   {
      return [
         'a_field' => '',
         'b_field' => 'max:255'
      ];
   }

}

And then, bind it to override all dependencies of the project:

class AppServiceProvider extends ServiceProvider
{

   public function register()
   {
      $this->app->bind(ParentImpl::class, ChildImpl::class);
   }

}
  • 写回答

1条回答 默认 最新

  • dongzhang4301 2016-08-22 14:14
    关注

    Talking with a teacher of mine, he said I can't do a perfect job. I'll always have to re-work on it. What I asked maybe isn't a wrong pattern, but the concept of the software probably is wrong.

    I'll make a lot of base packages in minor scale, in a way of let it easier to refactor. When some customer ask for a new feature or a new business rule I develop it.

    Develop software extremely abstract maybe wrong. It can do everything and don't be specific for the customer's need. It always has to be analysed. There is no rule, every software is a different story

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献