Modeldraw
  • Welcome to Modeldraw
  • Getting Started
    • Quickstart Guide
  • FAQ
  • UML Designer
    • Common Elements
      • Comment
      • Comment Link
      • Dependency
      • Realization
      • Frame
    • Class Diagrams
      • Class
      • Association
      • Generalization
      • Composition
      • Aggregation
      • Enumeration
      • Interface
      • Association Class Link
      • Ball (Interface Realization)
      • Socket (Required Interface)
    • Sequence Diagrams
      • Lifeline
      • Activation Bar
      • Synchronous Message
      • Asynchronous Message
      • Return Message
      • Found Message
      • Interaction Frame
    • Use Case Diagrams
      • Actor
      • Use Case
      • Association
      • System Boundary
      • Generalization
      • Include Relationship
      • Extend Relationship
    • State Machine Diagrams
      • State
      • Initial State
      • Final State
      • Transition
      • Superstate
      • Concurrent Boundary
      • History Pseudostate
      • History Transition
    • Package Diagrams
      • Package
    • Deployment Diagrams
      • Node
      • Communication Path
      • Deployed Artifact
      • Internet
    • Activity Diagrams
      • Initial Node
      • Activity Final
      • Action
      • Flow
      • Decision / Merge
      • Fork / Join
      • Partitions
      • Flow Final
      • Send Signal
      • Accept Signal
      • Time Signal
    • Component Diagrams
      • Component
      • Ball (Interface Realization)
      • Socket (Required Interface)
    • Communication Diagrams
      • Object
      • Link
  • Wireframes
    • Views
    • Layouts
    • Components
Powered by GitBook
On this page
  • Understanding Interface
  • Representing Interface Methods in Implementing Classes
  • Adding a Realization
  • Adding an Existing Interface to a Diagram
  1. UML Designer
  2. Class Diagrams

Interface

PreviousEnumerationNextAssociation Class Link

Last updated 7 months ago

An Interface in UML and object-oriented programming is a contract that specifies a set of public methods that a Class must implement. In Modeldraw, you can use Interfaces to define common behavior that can be implemented by multiple Classes, promoting code reusability and defining clear contracts between different parts of your system.

Understanding Interface

An Interface represents a collection of abstract methods and (sometimes) constants that define a specific behavior. Key characteristics include:

  • It declares methods but doesn't implement them

  • A Class can implement multiple Interfaces

  • It establishes a contract that implementing Classes must fulfill

  • Interfaces support a form of multiple inheritance in languages that don't allow Class-based multiple inheritance

An Interface is represented in UML by a rectangle similar to a Class, but with the «interface» stereotype.

Representing Interface Methods in Implementing Classes

It's important to note that there are two common approaches to representing methods from implemented Interfaces in UML Class diagrams:

  1. Omission: As shown in the example above, the methods defined in the Interface are not repeated in the implementing Classes. This approach reduces clutter and redundancy in the diagram, especially when dealing with multiple Interfaces or complex Class hierarchies.

  2. Explicit listing: Alternatively, you might choose to list all methods in the implementing Classes, including those inherited from Interfaces. This approach provides a complete view of each Class's capabilities at a glance.

Both approaches are valid, and the choice often depends on:

  • The complexity of your diagram

  • The level of detail required

  • Your team's or organization's modeling guidelines

  • The specific purpose of the diagram (e.g., high-level overview vs. detailed design)

In Modeldraw, you have the flexibility to use either approach. If you choose to omit the Interface methods in the implementing Classes, the Realization relationship clearly shows that these methods are indeed part of the Class's contract.

Adding a Realization

To create a Realization between a Class and an Interface:

  1. Select the Realization tool from the toolbox

  2. Click on a Class that implements the Interface

  3. Move above and click the Interface

Adding an Existing Interface to a Diagram

To add an existing Interface to a diagram:

  1. Open the diagram you want to add the Interface to

  2. Drag and drop the Interface from the navigation tree into the diagram

An Interface that is realized by two Classes