Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Super class that extends from Presented*****Layout #17

Open
jjvargas opened this issue Oct 23, 2015 · 3 comments
Open

Super class that extends from Presented*****Layout #17

jjvargas opened this issue Oct 23, 2015 · 3 comments

Comments

@jjvargas
Copy link

There is no multiple inheritance, but I would like to know if somehow it's possible to create a base class that extends from any of the Presented****Layouts.

@lukaspili
Copy link
Owner

I'm not sure I understand. Can you write a sample code, even if it's not compiler-valid?

@jjvargas
Copy link
Author

So I have two different Views

public class SearchGridMusicView extends PresentedLinearLayout
public class HomeView extends PresentedScrollView

And I want to create a base class for both

public class BaseView extends PresentedLinearLayout,PresentedScrollView

So I can use it like

public class SearchGridMusicView  extends BaseView 
public class HomeView extends BaseView 

@lukaspili
Copy link
Owner

Yeah this is the problem with inheritance (and Android relies much on it), because it's not flexible at all.
The only easy fix I see is for your 2 views to have the same base layout, like a FrameLayout. And then each one adds its custom layout LinearLayout and ScrollView.
The drawback would be that Android will render a useless FrameLayout, but the cost is negligible.

I don't know what's in your BaseView class, but it may be possible to apply the composition pattern rather than inheritance. Also, if you are a Kotlin user, you would may be able to use Traits to solve this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants