i using laravel build system, system complex , contains many if else, want change , clean code easier maintain.
i have this
if(a) { call_a(); } else { if(b) { call_a(); } else { if() { call_b(); } else { if(c) { call_a(); } else { call_b(); } } } }
of course more , more complex.
any ? thanks
i think know looking for. this post webstrous on reddit:
now time learn polymorphism.
you didn't specify in post if doing object-oriented development in php. if aren't, stuck if , case statements, if are, in luck. polymorphism invented, in part, eliminate kind of code describing - indefinitely long lists of conditional statements.
the basic idea, in case, whatever behaviour trying describe, depends on value of variable, may better encapsulated in class , subclasses. application's point of view, then, every instance of class looks same, internally, each object implement different solution.
here's quick example of inheritance in php, though depending on particular situation, other polymorphic approaches may better.
it spend bit of time reading this. don't think code much. polymorphism exists in object-oriented languages, , you're better off challenging understand concept. personally, i'm spending lot of time reading javascript design patterns, because that's domain right now, perhaps else can suggest comparable book php.
Comments
Post a Comment