class - Reusability and Extensibility in OOPL -


i have 3 problems, more or less similar.

  1. given integer array, want find longest continuous subarray, such subarray in increasing order of numbers.

  2. given integer array, want find longest continuous subarray, such subarray have same numbers.

  3. given character array, want find longest continuous subarray, such subarray have same characters.

i want exploit concepts of reusability , extensibility in oops. have implemented code using templates. have gave try , made class template problem 2 , 3 since both can done comparing ascii value of number or character. not sure how integrate code problem 1? want know how tackle such problems perspective of reusability , extensibility using inheritance.

strategy pattern rescue: can define interface encapsulates matching strategy, subarraymatcher , create 2 implementations, 1 matches "increasing order of values" , matches "same values". main algorithm can take interface parameter , call out matching.

high-level structure in pseudo-code:

array<t> findlongestsubarray(array<t> values, subarraymatcher<t> matcher);  interface subarraymatcher<t> class increasingsubarraymatcher<t> implements subarraymatcher<t> class constantsubarraymatcher<t> implements subarraymatcher<t> 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -