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

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

Related

Show UML Class diagram autopopulating class dependencies

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?

The components of a Class Diagram and how it differs to ERD

I want to understand a class diagram more fully and I am finding lots of conflicting information.
My first question is, what is the difference between class diagram and ERD? Not necessarily in look, but in classification. e.g. I have read that a class diagram is a type of ERD and I have read that a class diagram and an ERD are two different things.
My second question is around how the class diagram should look, I was given a basic tutorial on how to create a class diagram and I was taught that each class should be connected with a single line, with an arrow that looks like a 'Play' symbol (example 1 in the attached image)
But since doing some research into it, I am finding lots of examples where different connectors are used to denote association, aggregation, composition, inheritance etc. (example 2 in the attached image)
As mine is more simplistic, just showing the relationship and the multiplicities, does that mean that I have just learned a more basic version of class diagram and the extra connectors are an advanced step?
Or are they both something different?
Thanks for your help
Holly
First of all, welcome to Stack Overflow!
A class diagram is a type of static structure diagram that describes the structure of a system by showing the system's classes, their attributes, operations (or methods), and the relationships among objects. Wiki link
An entity relationship diagram (ERD) shows the relationships of entity sets stored in a database. Link
Therefore the answer to your question of "what is the difference between class diagram and ERD"?
The class diagram has nothing to do with fact how the classes are persisted in the data layer. It shows only the logical relationship between classes and the properties of the classes. While the ERD diagram illustrates the logical structure of database; what the database tables, table-column, primary keys, foreign keys, etc. are, and last but not least the relationships between database tables.
As for the question "Is this just a more advanced version of class diagram? Or a more updated version?":
There are cases when the ERD diagram can look similar to the corresponding class diagram, but the persistence data model can be way different from the class (domain) model. Furthermore a class diagram has no any information about how a class is persisted in the database - as I've already mentioned -, therefore an ERD has other kind of information than a class diagram.
As for the notations you linked:
A proper class diagram contains notations like in the second link. An example is the following diagram:
For more info what those arrows mean, click here for the corresponding SO answer.
What you are taught about how to make a class diagram (like at the first link you shown), can also be useful but it is a customized class diagram rather than an proper class diagram following the UML standards and notations because:
I find it strange that the arrow is not on the line itself
There is a shared ownership relationship (aggregation) between Customer and Vehicle. It means that a Customer can have (own) a Vehicle but the Vehicle can still exist as its own, without a Customer. This relationship can be represented with the aggregation notation. (See arrow 5a, or the class diagram below)
I find it also strange that a vehicle can have multiple Customers, as you notated with "0..*". But of course it is possible, since I do not know what kind of domain you try to model with the diagram...I made an UML diagram with proper signs, check this out:
Summing up, it is wise to follow the UML standards and conventions, since it is widely accepted and known so the information can be exchanged as efficient as possible, without misunderstanding.

calculating coupling and cohesion metrics from XML class diagrm

I am trying to create a project to provide decision making support for class responsibility assignment problem using particle swarm optimization. A fitness function is derived considering various parameters like coupling and cohesion and particle swarm optimization is to be carried out. The input to the program will be an UML class diagram in XML format. How do i calculate the following parameters from the UML class diagram in XML format :
MAC(c) - method-attribute coupling between class c and
other classes – Total number of interactions between methods
of one class (c) and the attributes of other classes in the same
class diagram
MMC(c) - method-method coupling between class c and
other classes– Total number of interactions between methods
of a class (c) and methods of other classes in the same class
diagram
MGC(c) method-generalization coupling – This is applicable
only in those class diagrams where generalization is applied.
RCI(c) ratio of cohesive interactions of class
c : RCI(c) = |CI(c)| / |CImax(c)|.
CImax(c) is the maximum possible cohesive interactions in a
class c.
CI(c) is the number of existing cohesive interactions
in a class c.
TCC(c) tight class cohesion - is the pairs of methods, m1 and
m2, of a class c∈C with common usage.
DMA (m,a) direct method–attribute dependency between
method m and attribute a.
DMM (m1,m) direct method–method dependency between
m1 and m2 .
How do i calculate these parameters from the UML class diagram in XML format?
You need to figure out how to deserialise that file into an object representation, one against which you can write an algorithm to do your things.
It is hard to provide help without more information.
The file you have, is it an XMI file? You can answer this by opening it up and searching for xmlns:xmi="http://www.omg.org/XMI"; if found, then yes.
Is the file an instance of Ecore? You can answer this by searching for ecore:; if found, then yes.
If the file is an XMI representation of a class diagram, and an instance of Ecore then you must open it with Eclipse Modeling Tools. If you manage to open it that way, then your next step would be to familiarise yourself with the Eclipse Modeling Framework (EMF) before writing algorithms which can traverse the class diagram as if it was any other graph-like data structure.
I am aware that my answer is a long shot; even if wrong, I would prefer to keep it here for others to strumble upon, namely those which are trying to open XML representations of class diagrams.

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.

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/)