dimanche 18 octobre 2020

How would you represent this code in UML, and which design pattern does it represent?

I am supplying an SDK (mySdk) that partially wraps another SDK (otherSdk), but not all of it.
Some application used to consume otherSdk, and now it will consume mySdk instead.
I planned this Java code (simplified):

// other (base) sdk //

package com.otherSdk.obj;
public class OtherObj implements IObj {
  protected void func1() { ... }
  protected void func2() { ... }
}

// my sdk //

package com.mySdk.manager;
public class MySdkManager {
  static MySdkManager getSharedInstance() { return mSharedInstance; }
  ...
  public void initMySdk() { ... }
  public void registerObj(MyObj obj) { ... }
}

package com.mySdk.obj;
public class MyObj extends OtherObj {
  public MyObj() {
    super();
    MySdkManager.getSharedInstance().registerObj(this);
  }

  @Override 
  protected void func1() { ... }
}

// Application code - now consumes mySdk instead of otherSdk //

Public class AppObjImpl extends MyObj {
  @Override 
  protected void func2() { ... }
}
...
MySdkManager.getSharedInstance().initMySdk();
...
mMyAppObj = new AppObjImpl() { ... }
...

But I don't know how to document and explain my architecture.

  1. How would you represent the component architecture in a UML component diagram (who contains what) (*)
  2. How would you represent the App instantiating the AppObjImpl in a UML sequence diagram (*)
  3. How would you call the Design Pattern I am implementing in MyObj?

(*) preferably use PlantUml compliant syntax

Aucun commentaire:

Enregistrer un commentaire