Android Java - Architecture Diagrams with PlantUML, J8 Method References

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this episode of my Android Java programming I'm going to explain an excellent modeling and visualization tool which I learned about a couple of months ago but I didn't use it haven't used it so far in real situation just some experimenting but because today my application is getting shape so I going to show how to use a tool like that the good thing that it is called plant UML and this plant UML is nicely supported by a tool called navigator what kind of navigator is that I think in preferences [Music] yes installed plugins yes markdown Navigator this Martin Navigator has when when you installed even the free version supports nicely plant UML diagrams if you are interested just check out the plant URL the web site this is not going to be a tutorial what I'm going to show how I use for a real application development situation the file is available here in mind this is the file I created mode the module architecture dot P UML and then with this this is the this file it's a text file and also a brilliant I would call it a kind of artificial Microsoft used to have a very similar brilliant tool and but this one is maybe not that fancy as the Microsoft ool was some graphing tool but this is good enough either and interestingly the color scheme the default color scheme is very similar to rational rose yellow and burgundy coloring anyhow so that's this it was my original architecture drawing just a sketch where I have the packages meaning this package sim was b1 as are the modules this is for the repository and data sources actually the API this is the package which has all the components doing let's call it the business logic and then has the communication towards a say P business one service layer on top of all of them I have a model this model is independent of everything these are Jack actually just more or less plain old Java objects serializable and this is the territory of JSON and JSON structure so this in my architecture this model is going to be used directly by everyone because it doesn't depend on anything they are just so view model now let's first discuss the AP P this is the application the user interface component that's where we have these activities login activity these are the fancy names in Android for the screens the activity is actually more or less the screen of course within an activity you can have fragments so therefore an activity screen could have a number of layouts these core fragments and then this user interface actually this is the application and all the data behind on the screen so normally the screens these activities shouldn't have any instance variable at least a non-technical instance variable so all the data that are relevant to our application should reside in view models and this is the architecture this is a view model a model view viewmodel architecture which I think maybe Microsoft invented it at least promoted their xamarin forms architecture which was really brilliant at architecture and then exactly the same architecture was adopted by Google team to to promote this model view viewmodel architecture and in this architecture the idea is that every user interface significant user interface component or a group of components has a background view model component and all the data application specific data are residing here all the application logic decisions are made here for example obligation components and then this is the application I would call this application logic inverses the business logic and this application logic of view model is responsible to keep contact with the business logic layer and then a channeling the actions from the activities the user impetus towards the business one business one of the business logic layer as well as when the data are receiving received normally typically in an asynchronous way channeling back to the user interface using live data so this is the architecture I'm going to model with my application with this plant UML I don't write everything but I just want to make it how to say more up today because in the meantime I first initially create this diagram I have [Music] modified the names mostly the names let's come to the b-1s lis of the model layer this is independent okay I would definitely we I don't have model so this way you will have the how it is used so instead of a user let me just really replace this user maybe with a be one session be one session be one session and I think this is called [Music] replace yes this is what I was looking for we placed a user be one okay and immediately the diagram is updated and then let me just add additional model elements like b1 activity I don't include the technical b1 error or B one exception login request they are not that important b1 activity is definitely interesting so when I entered here this is a these are components this is the syntax for components I'm using only components here I could use also classes but for this demonstration I use only components and b1 activity and then this b1 activity has a relationship with the b1 activities and then this is a list [Music] be one yeah this is the composition anyhow just leave it a simple line I don't remember what is the symbol now let's check out in the plenty warm all documentation what is the syntax for component diagram let me see what do I have here I don't find the line I am looking for okay then let's go back and see if I have a class diagram yes composition aggregation and expansion okay I think this is what maybe this one aha I think I can use this this is a multiplicity specification so this is the symbol let's come back oh but it doesn't didn't work that way very interesting that here it is not complaining okay then let's use this other is X we don't know why it is not supported interesting that they are included here maybe it doesn't support the okay then let's have at least this direction that is a big one now the other way is correct the b1 activities has relationship it'll be one activity b1 activities is a practically a list of the components so this is activities okay so for now that's that's fine let's move on to the b1 s maybe login data source okay this is b1 s looking data source I just renamed it again let's rename this datasource and replace it with a lot longer name the one belonging data source maybe in implement okay and then also this log in the ass let's just replace that with one source and interface yes yes b1 datasource interface and then let me just add another component and this is the one activities source this is the implementation this is the Java class and it provides an interface implements an interface called exactly the same name this is how it looks source interface and I also include the retrofit interface b1 is raw sweet if you are familiar with retrofit you know what I am talking about and this implementation is using that interface so therefore the dependency is for example yes this is the dependency so the interface is provides uh-huh but this is not a package this is just an interface exactly this is just an interface just like this this is not a package this is an interface excellence or datasource implement it uses them depends on the retrofit interface and provides the activist datasource interface and repository and the repository should be renamed to data source repository betta source repository here you go tender this data source repository also has dependency towards the list implementation yes because this database repository this is a factory and then whenever someone is yet lomi I guess this is also renamed let's check out in the source file in this repository what interface it has it has a get active get login it's remains the same but it also has a get activities function and then this function is available to the view model classes so yes greater source of history also provides this interface okay but it's from there anyhow doesn't matter and the up view model the up view model I have here this has also dependency on this interface so up your model I just copy this [Music] this is wrong this is a dependency sorry this is the dependency so the way it works the the up view model when it requires service from the b-1s module the fact it has a reference to the data source repository via these two functions either calls the GATT activities ds4 the get login D s and then based on the implementation the data says repository returns either the login data source implementation but the view model is exposed to use only this interface so therefore let's just add another dependency this is terribly important that we are using here the low-beam datasource interface as well as the activities data sourcing their face yes this is what we have here so if the up view model because a get activities the yes for example and then the data source factory creates an instance of this be one activity data source implementation which has this data source interface and then this is what a few model is actually using that's why we have this dependency here so definitely when you want to draw just an overview diagram this is not an overview diagram this is more so but it shows you the intricacies and the details and their internal dependencies of this application so the retrofit interface is never exposed to outside so it's not really used outside of this v1 as so that's why it is also very important at as well as we have another retrofit interface here and this one is the login retrofit interface let's come back to the package we I have here the retrofit interface let's copy this one and this retrofit interface instead of the retrofit interface when the name is B login login retrofit interface and it is implemented it's used by the login data source implementation yes so the nice thing with this plant humor support of this navigation plug-in is that you have so when you define your components it shows you that what components are available yeah so this is here our my understanding that we have some possibility to rearrange our drawing when you something like that this way maybe it's easier to to layout and for example if we want this to be down I think we can until this is the b1 activities yes this one I think here we can enter characters ID meaning down and that this is not what I wanted what I want yes these are the possibilities what we had that they didn't have a lot so let me just move it the other direction actually it is fun to work with when you know what you are doing yes now it it's okay fish I don't understand why this is so far away from this login data source interface moving data source why not just make it on the other side no maybe now he doesn't want to move down down is the default sorry and up whoa Wow now I think this this is this is now what I like so this is the way you can so you means up so now you have some option to arrange your diagram somehow and what is interesting though and of course also this implementation is using the service layer but not directly or let's go not really directly but via this login retrofit interface so from login data source I move this line to the login retrofit interface b1 login data source in flow and not to the service layer instead login retrofit yeah it's not a package and yes so now we have all the channel and also v1 activities okay cool so that is now we had given activities retrofit interface or to this retrofit interface actually are used for the communication with the business one service layer yes so so this is the b-1s package let's concentrate now application view is just two objects nothing special the model I have already covered the b1 activities yes that's who is using actually these are really used by all the older applications so you can draw your diagrams here and there but because this login activity now is in in just an experimenting face so at the moment it has direct access to the b1 activities but definitely we can draw a line from there to just sake of complex completeness let's do it that the login activity has a dependency you get lovingly instead we have activities yes yes this is logging activity and now it has dependence it is everyone activities so yes it uses the be one session a be one activities either and then use these two services and then let's concentrate on the view model now at view model it's okay and view model factories to say but we have also two interfaces and two functions yes this one is I login vm i rename to be one login vm int okay so here i rename this i login let's rename it the one log in the end so this is now the correct name they get login VM let me see if this is the name because in the factory if you have yes get login VM and get activities VM so these are the two functions that returns actually the view model the trick here is that in every case this the view model is created but the trick is that this view model provider always returns the same object so it's really a fancy way this is the Android architecture component anyway so we have also the got activities VM so let's add this get activities VM to mm-hmm yes I have these got activities which is also used by the login from the package you get activity as we okay it is significantly redrawn so the view model notice so this is the application now has dependency so two interfaces two functions to get you model Factory okay cool a few model and after view model implements the login vm interface as well as the this login via an interface and also the one activities via an interface yes this is another interface and the login activity is using is dependent on this too these are interfaces I don't know why I used here these package syntax activity SVM interface so login activity now has all the dependencies yes excellent so a scene the login activity has all its dependency via the view Moodle Factory and then all the actual transactions are done via these two interfaces a few model so a good architecture especially in Java or dart c-sharp even in types typescript where the concept of the interface are available this is typical because when you have an interface actually the only thing you have to do is when you want to understand the architecture of your system first after you have a diagram user checks check out for example what is this maybe last year maybe this this one log in via me interface he opened this you can see immediately what are the possibilities first of all this view model provides live data streams to be watched of course these are the data where the activity the user interface has the data the login form State login result value be one session logout result it's just a regular in and then the error handling so these are the channels normally if you want to implement this in your activity you have to consider that have I implemented this stream have I implemented so these are the values which are pumped as a streams towards from the view model towards the activity and then here comes the other direction when this is absolutely not important when I really hate it I will delete it f in Italy just over complicates our life the other direction these are the services these are the event the entry points of the events that you could use from your user interface the login aceing login data changed and logout acing because this is for the login via me interface I show the other interface what does it mean that pay attention that when you use this log the user interface the login activity the screen calls the login acing function the async is terribly important in my opinion because now you are sure that this login will return immediately but behind the scene it starts doing something and then it returns the value via any of these channels in this case the login result which is written to be one session asynchronously or the error the error handling is terribly important all business applications the data login data changed here is just a validation doesn't have the suffix acing meaning this is a synchronous that is just for for validation and you can you receive immediately the response from this function and look out I think is similar to the log out that logout result and this law to inform state is just another cool thing and then the other viewmodel interface is the v1 activities where again the concept is similar get activities actually this is that very acted result of the query activities and then again error handling and query activities acing and let me show you immediately tricky thing that in application how these view models are retrieved I received for example in my case here we go so this is where the view model is connected to the activity at the moment this is not using the data binding the next iteration I will rework the whole thing using data binding actually this is more or less the way this Android studio visa generated it but of course I modified it significantly but I haven't already implemented data binding so login VM get the login VM so behind this view model Factory is actually using the Android architecture lifecycle management to get the proper view model for that and then because this is the login via VM is just an interface so from this perspective the activity doesn't have any clue how behind the scene is it was implemented but actually in my case I have two interfaces to provide more modularity modularity it's not necessarily from the of the architecture itself but for the project management so when you are working in a team you may have a separate team who is responsible of working with the login interface another team working with the activities interface and actually yes these two teams are working in a modular way in multiple modules but at the end from the perspective they are visible as they are separate but here there is a trick that this activity checks if the login VM is exactly the same it has it it does it implement the b1 activities we have interface yes its finds that it acts so that's its you can safely then you can say we just simply have to say use the same same reference it is got it casting and then if this is not the case only then cause the view model Factory to get the active assist you model because in that case possibly the view model Factory is creating a separate view model for this activity so that's a possibility and then the activity the user interface screen is really independent so unfortunately in my case this b1 activities has nothing to do with the Android activity Android activity is a screen business one activity is a task phone call or something like that so this is a business concept that's why I practice it b1 activity right and then back to our diagram this is modeled nicely here and then when you have a diagram like so you can explain and visualize these dependencies a lot and then why you are writing making these diagrams the one of the big advantage you always you the architect the designer has the option to review rethink validate if your design is are is okay every component are available and everything are in place so this is typically an application where you can expect in my opinion two or three people would be optimal to implement it one by writing the business one part and components and another one for the view model as well as the user interface and the third one is maybe just implement the corresponding components in the service layer in the in the business one side tables use the tables user-defined fields and these things I think that's all what I wanted to show today before leaving let me just come back quickly to this login activity what fancy thing has been done here first of all miss London so this was the original syntax in Java 7 this new observer and over I public and then later we have here another lambda expression like so and then when you have again this method reference possibility to have this reminder so therefore I implemented my observers like so get login resolve observe and unchanged login result unchanged logout result unchanged activities and these are this this this is the method reference that here I have all of them at the bottom and this way in my opinion I prefer this a lot better than then applying for exam this style these anonymous objects and classes defined the the reason I prefer this because then these components has names and when you have names you have the option to design them to reference them here in your diagrams in your modeling tools if you are working the the anonymous objects and classes like so then it's very hard to model them for example check out this one this is a login form state and therefore how do you hold can you model it it doesn't have any name it just an anonymous observer implementation here so that's why I think for a complex application where documentation is is important maybe this is the way that work and then what is good with this that you can use this very simple technique so to me this technique is more like a declarative way of programming rather than this this to me seems really cumbersome then this other way so anyhow this is what I wanted to show so I'm definitely love this method referencing tax read with my that you should know that what's going to happen here so you need definitely some experience first when you read someone else's code that when you can see these double colons be reminded that this is this method reference and then if you really want to understand what's going to happen here you have to go to the declaration to see aha so this ring here expects a be one session be one session is handled accordingly in the last episode I had a crash yes I think that was the reason of the clash and actually I didn't regard it as a warning but Java warned me that this is a potential error and actually it is because it may be now and therefore ID number of activities here I'd prefer to extend this a bit [Music] if this is null then let me turn zero otherwise return besides we have to send which into this if I'm not mistaken yes the gate value may produce new for inter exception yes because this this is movable actually this is not knowable it it may happen of course if we really want to be hundred percent sure because this is nullable white is movable because we never pump van using - no let's change it - no no okay this warning goes away and also the one activities so definitely our our view model we have done it says it's not linear right because this is not movable and then it's really the responsibility of the view model and our application do not push into these light data streams null values U is pushed means that it was cleared but that could be the discussion for another session
Info
Channel: Miklos Nemeth
Views: 2,527
Rating: undefined out of 5
Keywords:
Id: RWN-wf34p5Q
Channel Id: undefined
Length: 58min 39sec (3519 seconds)
Published: Tue Aug 20 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.