0
devapsarl
12d

What do u think guys about the generic idea to add static methods in a class that will be some sort of "thematic helpers" that will be used in the whole app ?

Comments
  • 0
  • 1
    You lost me at "thematic helpers" and "whole app" , there's something not quite right about calling a helper function / method from a global layer.
  • 1
    I guess you can have a Helpers namespace for a framework, such as Laravel that have its Str and Arr classes.
    For an app, and all of it? Why is my question
  • 0
    A tiny change and make it a factory pattern. Less of a mess
  • 0
    Bad idea) you wouldn't be able to reuse your code in future and it's look messy, just get best from OOP and SOLID it will help you in future projects
  • 1
    I may have not expressed my self properly.
    Lets say you create a class ServerRequest, that encapsulate the android AsyncHttpRequest from loopj.
    In the constructure u create the client et configure it.
    In the private fields u have the host url and all api endpoint as statis constants.
    And some public methods for post and get request.
    And an empty public overridable method called "processresponse".

    So far this is the normal oop i use.
    But my idea in " thematic helpers" is that, since that class manage connection between my app and the backend why cant i make it manage more of the things related to that app-backend connexion ? ?

    Like for example adding a static method that takes Context in arg and check internet connectivity and redirect user to android setting page ?

    This helper may be used outside of the only purpose of the class itself,

    Dunno if i am bit more clearer
  • 1
    @devapsarl Having all stuff in single class may break single responsibility principle, but since it's an Android app I'm not think it's so critical when you don't have large enterprise solution with bunch of devs and testers who will work and test your code. Otherwise, it is better to build right practice as habit, it will help in future
  • 0
    @Leonid
    Thx mate for the advice.
    Can u clarify what this single responsabiliy principe is made for ? To avoid what scenarios ?
    What it is its pros and cons
  • 1
    @devapsarl single responsibility is just one of 5 principles of object oriented design known as S.O.L.I.D
    you should read this article for more information about all of them with examples in Java (if you use it for your android apps) http://blazorhelpwebsite.com/Blog/...
  • 1
    @devapsarl oh, sorry wrong link) this one https://dev.to/arpitmandliya/...
Add Comment