In an UML diagram, when should a class be abstract? Just when we want to prevent instantiation?
Edit: Can an abstract class fully implement a method (when the method only depends on the attributes of that abstract class)?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Preventing instantiation is a matter of implementation, so it is a good reason if you are thinking in terms of Java, C# etc.
However, on the level of modelling, you’d want to make a class abstract if there are several subclasses, and it makes no sense that an object is of the supertype but of neither of the subtypes.
So, basically you’re not preventing instantiation of the class, since any instance of the subclass is also an instance of the abstract superclass. What you are doing in that case is preventing instantiation of the superclass alone, i.e. enforce using one of the subtypes.
Answer to EDIT: Yes!