Class Diagram OOP - oop

If two classes are associated regularly, do they need to contain each other's objects as attributes? For example, a Post class and a Comment class on a social media platform. Should the Post class contain an array of comment objects as an attribute? And should the Comment class contain a post object as an attribute?

This is a common mistake of redundant information. It does not need to be shown in the class diagram as a field because it is derived from the association.
This is a class diagram that covers what you have mentioned in its simplest form.
As you can see, objects for each class do not need to be added as fields.

Related

Can only have a link to lifelines in Sequence Diagram if there is a link in UML classes?

Is there a must that in the UML class diagram, if two classes are not linked, then there cannot have a connection between those classes's lifeline? For example if I have a void function public void sample(actor a) since it's just a parameter so there is no link between two classes, but is it possible that in sequence diagram that that is a link between two to perform certain actions?
I think it can be and I actually found some images to prove it(not too sure if I have misunderstood the images) but my tutor says I'm wrong that there is no link between two lifelines if there is no link between two classes. So I'm not too sure about the answers.
Assuming that by "link" you actually mean "message" (solid arrow), you need an association. A message is equal to an invocation of a class' operation. To be able to do that, the caller must have a reference to the called class - an association.
No , is is not necessary to have association or any other relationship defined explicitly between classes which instances communicate in class diagrams. If you need to depict that instances of specific classes are connected in interaction (communicates) , you can use Collaboration element and connectors. Connector defines communication relationship, but does not define how it is physically implemented. In some cases it can by realized by link of course.
Message between lifelines implicitly defines communication relationship between lifeline's types.

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.

Need for Class/Data Structure

I am working on a project with class hierarchy as in the image. It has many classes but i am showing some of them. The problem is that there are some attributes that repeat in many classes but not in all classes. I want to reduce the occurance by creating a new class with common attributes, and use the class as Instance variable in all the classes. This way i can maintain my class instead of maintaining all the occurances all over the code. These attributes has no operation, and class also have methods so it does to fulfill the definition of class. The class has many levels of inheritance and if create subclasses, it has yo-yo problem then, so i do not want them to be further subclassed. I want to know is there any other way? or any better way to do it.
You have yo-yo problem when you have all concrete classes. I would suggest to make an abstract class and put all common attributes there. I also see that you have Unit value attributes repeating for same attribute. For this, you can use hash map to have only one attribute with two values for unit and for value.

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

Class diagram for objective C standards?

I'm having trouble finding the standard way a class diagram should be drawn for objective C applications. Mostly:
Do I incude field types or just the var name?
Do I include method return types and parameters?
Thank you!
Many of the Objective-C diagrams I have seen do not include types or parameters. Only the field and method names are placed in the diagram.
However, I would strongly encourage you to include all this information, regardless of what the norm may be. By doing so, the class diagram is not only useful for modelling, but also serves as documentation. It's not particularly difficult to add the type annotations, and the end result is a far more complete (and useful) picture of the class.
Document them the same way you would document a class in any other object oriented language. Class properties should include the field type, property name and multiplicity. Class methods should include return types and parameters.