Show UML Class diagram autopopulating class dependencies - intellij-idea

In IntelliJ IDEa, one can quickly create an UML Class diagram for any class or a set of classes. You can add classes to the diagram via drag and drop or using space key for that.
Then you can show dependencies between the classes. However, I'd like to see what are all the classes that interact with some specific class. If I show a diagram of that class only, I'll only get some inheritance in that diagram, but dependencies associations are not shown. For that I need to drag in all classes that I know interact with the class and then show dependencies. Usually I would just drag the whole package in, expecting that there are classes that interact with this class. But that will bring in a whole lot more unrelated classes and then the diagram explodes.
Is there some smart way of adding just classes that directly interact with my class, so the diagram scope is more limited? E.g. all class interacting with a class from a certain package?

Related

Are my class diagrams Correct?

I've made two class diagrams. But I am not sure if they are correct or not. These classes were in the same package and I used Visual Paradigm for making the class diagrams. However, I couldn't make one ReadOutputFileforBreastAndColonCancer class for both WeakSignalFilter class and StrongSignalFilterClass.
Therefore, I had to make two different class diagrams. Is it correct? Can I do it.
Help will be much appreciated.
Please refer to VP's support page, Creating class diagrams. First create the StrongSignalFilter class, then click its Aggregation -> Class resource beside it and drag to empty space of the diagram to create the ReadOutputFileforBreastAndColonCancer class. Next create the WeakSignalFilter class. Finally the crucial step: click the Aggregation -> Class resource beside the WeakSignalFilter class, and drag to the ReadOutputFileforBreastAndColonCancer class. This is how to create an association between two existing classes. And of course you can also create the three classes first before creating the two aggregrations.

Interfaces in UML component diagram

In the UML class diagram the interface is equivalent to the interface concept in programming languages (a set of methods that the class that implement the interface should implement). I want to know if the interface in the component diagram has the same meaning. Are the interfaces mentioned in the component diagram the same interfaces that are detailed in the class diagram or should I treat every method in the component diagram as a separate interface?
There is actually no real difference between both. You can realize an interface with a class as well as with a component. Also you can show the realization in both cases with the socket/lollipop notation.
Components are not much different to classes. You can think of a component as a container that hosts a number of different classes. And if one of those classes realizes an interface you can expose that through the component (if you so wish). Additionally a component can have a lot of internal interfaces for its hosted classes.

Instancing an Interface in Object Oriented Programming

I am trying to represent the following situation in a UML Class Diagram.
We have a class named Selection where the user select how will the
next screen be.
The selection class has a property screen: Screen, where screen is an interface.
There are multiple implementations of the interface screen. ex. SimpleScreen, SuperScreen, etc.
The screen property in selection class should be able to contain an instance of any implementation of screen depending on user choice.
My questions are:
Is it possible to do this in OO?
How would the Class Diagram representation look like for this case?
Right now I have a diagram like this: http://yuml.me/1dcb2f2f
If you want to modify the diagram I used yuml.me this is the link http://yuml.me/edit/1dcb2f2f
Thank you for your help
Yes it is possible to do it in OO. The correct UML notation is:
http://app.genmymodel.com/engine/xaelis/nextScreen.jpg
In order to act upon an abstract 'screen' polymorphically the implementations would have to adhere to a common interface or inherit from a common base class.
I'm not sure of the proper way to UML this, I think you've got the diagram about right.
Get acquainted with design patterns.
Use factory method (produce instance based on the user choice) +
singleton (makes factory easily accessible and ensures that only one factory exists) for producing instance of needed class +
object composition with bridge pattern(allows to decouple interface from implementation and allows to switch implementation in a run-time/)

What is the difference between Object-Graph and a class diagram?

Is there a difference in the meaning of "class diagram" and "object graph"?
see this tutorial
http://www.cs.toronto.edu/~jm/340S/Slides6/ClassD.pdf
Object graph contains value of one instance of class see example View its a view of an object system at a particular point in time
while
class diagram as wiki
The class diagram is the main building block of object oriented modelling. It is used both for general conceptual modelling of the systematics of the application, and for detailed modelling translating the models into programming code. Class diagrams can also be used for data modeling.[1] The classes in a class diagram represent both the main objects and or interactions in the application and the objects to be programmed. In the class diagram these classes are represented with boxes which contain three parts: [2]
A class with three sections.
The upper part holds the name of the class
The middle part contains the attributes of the class
The bottom part gives the methods or operations the class can take or undertake
see further
I agree with the previous post but would like to add that a class diagram is based on UML which is an accredited language sponsored by the OMG and known by over 5 millions users. UML is therefore a standard based on a model from which you get views.
IN UML 2 the class diagram is fantastic if used with Java because it seems to me that the new specification has exactly the same structure as a java project. It include a project name, with packages including classifiers (e.g. Class, interface, enum) which includes attributes, methodes which includes properties.
If you have to use just one diagram I would say to use Class diagram. It is easy to create because you don't need to know UML and can reverse engineer your project into a model a get class diagram views. My class diagram is Just magic:-)
Class diagram represent class name,its attributes and behaviours whereas object diagram represent instance of class diagram,object diagram comes under class diagram

Abstract classes vs interfaces to represent a family

Abstract classes are described as being useful for a family of objects (e.g. could be used for animals which are mammals). However, what difference is there between using an interface or abstract class for representing a family of related objects?
My process is to use an abstract class when I want to define common functionality but with the option for future extensions and an interface for custom functionality (implementations).
For example, I wrote an abstract class to encapsulate some database functionality which will be used heavily in a small web app at work. I wrote an abstract class with virtual methods which can be overrided with custom functionality in the future (e.g. logging, or some reporting of the database events which may be required).
Is this the right way to go? Is there any significance in choosing one construct (abstract or interface) to represent a family?
An abstract class should be used when there is common state and behavior between all types. An interface should be used when all types will have a common interface but will not share state or behavior.
Here is an example.
German Shepherd, Golden Retriever, Beagle
These three objects are all dogs, and as such they share certain common state (carnivorous, 4 legs, etc.) and they also share certain overridable behavior (bark, pant, etc.). In this instance it would make the most sense to create an abstract Dog class to hold this common state and behavior and create subtypes of Dog for each type of dog.
Pencil, Pen, Chalk
These objects have no common state and they cannot share behavior. Yet you may notice that they do have something in common - they are cabaple of writing. These objects are best build separately and without a base class and then tied together with a Writable interface that exposes each type's Write method.
I would suggest using interfaces so that you can implement new functionality in your database utility at some future point.
As always, the primary design principle when it comes to development is
Design towards an interface, not an implementation
With abstract classes, you can provide implementation that is needed and shared by all the classes in your hierarchy. Therefore, you're reusing code. You may allow the derived classes to override the default behavior or not but at least you're providing a baseline functionality like breathing for a new born animal. However, with interfaces, you can't provide any implementation. You simply define a contract that all classes that inherits that interface should honor and provide implementation for. This may lead to repetitive and duplicate code among the hierarchy of classes.
Interfaces are not very good for extensibility and you need to worry about versioning. You decide to make change to an existing interface but you will soon realize that there are a lot of classes in existence you may need to modify. Think about adding Breath method to IMammal interface that's already being used by many mammals. You will need to go and provide Breath implementation for each one. With an abstract class, you can simply add Breath method and provide some baseline implementation without having to worry about existing derived classes. So abstract classes are more flexible in term of the development of your hierarchy and the api.