How do I show REST API and Database Connection in UML Class Diagram? - rest

I am trying to Create Class Diagram for my Web Application but i dont know how to Represent Database Connection and REST API in Class diagrams.
P.S. I am Creating Class Diagram by following model view controller pattern.

A class is a class
In your class diagrams, you model classes of your system. And all the classes look alike:
a database connection would be a class like another, that will keep some properties about the database context and offer methods for connecting to and disconnecting from a given database.
a REST API class would be a class (or a set of classes) like any other. If you're the API consumer you would certainly have no properties in these classes (because REST is stateless and properties create a state). You could for example have a method for every service you could invoke.
Conceptually speaking theses classes in your system are proxies for something which is out of your system, and which would invoke the APIs provided by the database and the webservice.
But perhaps you want to model something else ?
If your system offers an API, and you want to show how the API offered to the external world relates to your internal classes, you could be interested in using a composite structure diagram.
If you want to show the different components if your system, especially how these are wired together using an API, you could be interested in the component diagram.
If your question is not so much about the structure of the classes and the deeper internals of your system, but more about showing that some part are on remote servers or in containers, you could even think of deployment diagrams. But these are more about the concrete layout of the operating infrastructure, and to link it to the classes, you'd need the component diagrams first.

Related

The logical way of class interconnections in a system

I am new to coding and I was wondering what is the logical way of representing the interconnections between classes of a system, more specifically the GUI class and the system's classes. Let's consider an online ordering system. In addition, let's consider that we need to make an order in this system. So I imagine that there is a GUI ( after logging in ) and there is a button for make order. So this means that the GUI class will be connected directly to the make order class ( if we assume that there is a class that is responsible for making orders )? Or there should be some intermediate class that should be connected to the GUI and controls the logic of the system ( if user choices make order then this control class deals with the make order class, if user choices to track order then this class deals with the track order class and so on )? I am looking for the most efficient way of writing code.
Edit: In many textbooks, they mention three types of classes that deal with this issue which are boundary class ( GUI), controller class and Logical class, but actually I don't know the exact meaning of the controller and the logical classes types.
MVC is one famous pattern used for this specific purpose. MVC stands for model view controller.
View = Classes responsible for the UI.
Model = This is the business domain where all complex business logic lives. OOP is heavily used here.
Controller = This connects the view with the model. Example - a click on the UI needs to be fulfilled by a model and the controller will connect the UI to that model.
Add REST to this mix which will help UI communicate with Model and the make the model agnostic to type of clients being Web, Mobile or even another server. Angular, React etc are heavily used for UI presentation.
You would needs a persistent layer to persist the state of the model and read it back. Example - A database which can save historical order and read them back. JPA and Hibernate are famous tools for this.
You don't need to deal this raw MVC, rather use one of many web frameworks which will take care of boiler plate code for you. Spring MVC is one such framework in Java world. There are equally famous frameworks for python, node, scala etc. This framework will have standard ways to do REST, Persistence, controller etc. So start from this.

Caliburn.Micro, MVVM and Business layer

I'm building a WPF application using MVVM pattern, and Caliburn.Micro is the framework choice to boost up the development.
Different from a conventional MVVM-based application, I add a business layer (BL) below the ViewModel (VM) layer to handle logic for specific business cases. VM is left with data binding and simple conversion/presentation logic. Below BL is an extra Data Access layer (DAL) that encapsulates the Data model (DM) underneath built with Entity Framework.
I'm pretty new to both WPF, MVVM and, of course, know almost nothing about Caliburn. I have read plenty of questions and answers about the Caliburn usage and now trying to use what I've learnt so far in my application.
My questions are:
Does it sound okay with the above layered architecture?
In the application bootstrapper, is it correct that we can register all services that will later be used (like EventAgreggator (EA), WindowManager or extra security and validation services), and also all the concerned VMs? These should be injected into VM instances via constructors or so (supposed I'll be using SimpleContainer). So from any VM that are properly designed and instantiated, we can have these services ready to be used. If I understand correctly, Caliburn and its IoC maintain a kind of global state so that different VMs can use and share it.
Navigation: I know this topic has been discussed so many times. But just to be sure I'm doing the right way: There'd be a ShellViewModel acting as the main window for the whole application with different VMs (or screens) loaded dynamically. Each VM can inherit either Screen or ViewModelBase or NotifyChangedBase. When I'm in, let's say, VM A and want to switch to VM B. I'd from inside VM A send a message (using EA) to the ShellViewModel, saying that I want to change to B. ShellViewModel receives the message and reloads its CurrentViewModel property. What should be a proper data structure to maintain the list of VMs to be loaded? How can stuffs like Conductor or WindowManger come into the place?
Can/Should Caliburn in one way or another support the access to the database (via EF). Or this access should be exposed to VM and/or BL only?
Thanks a lot!
Different from a conventional MVVM-based application, I add a business layer (BL) below the ViewModel (VM) layer
That's the standard case. ViewModels can't/shouldn't contain business logic which is considered to be part of the Model (Model in MVVM is considered a layer, not an object or data structure) in the MVVM. ViewModel is for presentation logic only.
Yes, as long as your Business (Domain) Layer has no dependency on the DAL (no reference to it's assembly). Repository interfaces should be defined in the Business Layer, their implementations in the Data Access Layer.
Yes, Bootstrapper is where you build your object graph (configuration the IoC container).
Registering ViewModels: Depends on IoC framework. Some frameworks let you resolve unregistered types, as long as they are not abstract or interfaces (i.e. Unity). Not sure about Caliburn, haven't used it. If the IoC supports it, you don't need to register them.
One possible way to do it. I prefer navigation services though, works better for passing around parameters to views and windows that are not yet instantiated and you always know there is exactly one objects handling it.
With messages, there could be 0, 1 or many objects listening to it. Up to you
What do you mean with support access to the database? You can use it to inject your repositories and/or services into your ViewModels, other than that there isn't much DB related stuff to it.

Suitable design pattern for business to persistence layers

I am using mongoDB that stores a simple product collection. I'm accessing this database from mongolab's API, so there is no direct access to the actual DB.
On the the other side, I have a Product model that has the same properties as the product document in the DB.
My question is: what design pattern(s) is(are) suitable in order to connect my business layer to the persistence layer.
So far I see these steps:
Product creation:
Create and populate the Product Model
Construct the endpoint URL for the API
Send request
Product retrieval:
Call methods like getProductByName() or getProductByCode()
Construct the endpoint URL for the API
Send request
Create and populate the Product Model based on the response.
I want to make the persistence layer as abstract as possible because in the future I might change the way I store and retrieve data. Also, this will be a simple application, so there is no need in using complicated logic or full ORMs.
Well I'm not an Android developer but I think my answer might be helpful. If your persistence layer is really simple and you are just going to have several methods there, there's no reason to complicate it with overdesign. Here's what I would do if I were you:
Add a new project to the solution for DAL layer.
Create a contract/interface with all methods you need.
Add all DTO's you might need to serve as input or output parameters for the methods.
Create a repository class which implements the interface. make sure it deals with all the API stuff (constructing the endpoint, etc.)
Reference the newly created library in your business layer. Make sure you use IoC to instantiate it. It's important you always reference the interface not the class itself.
Add some mapping logic between your business layer stuff and persistence layer DTO's
Now if you want to store your data in a database directly or whatever, you will need to create one more class which implements the interface and replace the old one. The rest of your code will remain untouched. Btw, it will be easy to mock the persistence layer for unit tests then.
Hope it helps.

View and Servlets in website class-diagram?

I'm about to develop this small website, its basically a simple web app to store informations about patients for a doctor.
The company i have got the assignment from demands an introducton with a class diagram, honstly, i have done this already but only for standalone apps, i'm very new in designing class diagrams for websites.
What i'm using is the Ivar Jacobson's iterative metho with usecases, where a usecase includes:
Actors, scenario (representing user-system interactions when all goes fine), and worse case scenatio (solutions when something goes wrong).
By applying this i came to a good conclusion, a well prepared class diagram.
My problem is that i'm doubting whether or not i should include jsp views and servlets(in my case action beans since i use Stripes) in the diagram, i mean, the bridge between the business-classes and the user are the jsp-views and the provided info are going to be processed by the servlets (or action beans), would you include them in the class diagram?
For a small project tis might be not that relevant but what if you have a project with 30 views and 20 servlets, the diagram would become messy and huge.
Do you have some tips about it?
Thank you
If the only reason you need the class diagram is to satisfy the client, best find out what they're looking for first.
If however they're not specific (and ignoring the cynical options) I'd suggest the following:
Create a "Domain Model" diagram. i.e. capture the concepts in the domain and their inter-relationships. So Doctor, Patients and associated stuff.
Don't create a "design" class diagram - i.e. no jsps, servlets, etc. If necessary create a simple architecture picture instead showing how the application is layered.
Rationale: a domain model is good for checking scope and verifying domain rules (relationships). A "design" class diagram only obfuscates that. A proliferation of jsps, controllers, etc. hides the underlying architecture pattern while distracting from the useful stuff in the domain model.
hth.

IoC and events

I am having a really hard time reconciling IoC, interfaces, and events. Let's see if I can explain this without writing a book.
I'm just getting started with IoC and I'm playing with Spring. We have a simple data layer that was built long before EF or the others. One of the classes is a DBProcedure which has some methods and events.
I created an IDBProcedure interface that the 'real' DBProcedure class implements. In TDD fashion I'd like to be able to swap out the 'real' DBProcedure class for another that implements the same interface for testing. To me, this means that the IDBProcedure interface should be defind in a different namespace/project than my data layer, right?
But a DBProcedure can raise some events and those events deliver custom EventArgs-derived classes. Does that mean that the EventArgs-classes need to be defined outside the data layer too? Seems like it to make the interface work, but that seems bad because it spreads data-layerness around?
On the other hand maybe I have the wrong idea - is it ok to include the data layer namespace when I'm testing to get interface and event definitions even though I'm not using any of the 'real' classes?
Yes, you need to move the interfaces and all the types it depends on somewhere, because you do not want the interfaces module to depend on the implementations.
The typical choice for this is one of two alternatives
Impl ----> Api <---- client
(Implementation depends on api, client depends on api, everything in api module)
Impl ----> Api <----- client
\ | /
\ V /
------->Model<------
Here everyone depends on a common "model" module, and this contains the enums and such. The advantage of this version is that you can have multiple API modules share the same common enums and other artifacts. (Because you really don't want API's to depend on other API modules usually)