Nesting packages and classes inside components in Sparx Enterprise Architect (EA) - namespaces

In the software model I created using EA 13, my top-level nodes contain packages. Each package contains components, which can also contain sub-components. There are several levels of sub-sub-components. Finally, the detailed design of each component is represented by class diagrams under each sub-sub-sub[...]-component. My classes are contained in the software component they describe.
I would like to be able to separate my classes into several packages, mimicking the Java package structure of the corresponding implementation. My problem is that it is not possible for a EA component to contain a package. If I create a package in the class diagram, then it will appear at the same level as the highest-level component in the Project Browser.
My expectation: Root Node / Package / Component / Sub-component / Java package / Class
What I obtain: Root Node / Package / Java package / Component / Sub-component / Class
The only workaround I have found is to create a component to emulate the Java package, but I feel like I am twisting EA.
Is there a way to achieve this? Or am I completely missing something?
Thank you.

You aren't missing anything. Only packages can contain packages. I haven't checked the UML specs since I'm used to that since ages. The only way to mimick a package structure is to create stereotyped classes (using your own profile). EA offers a PackagingComponent, but that's a stereotyped package and can not be placed inside of elements either.
You could send a feature request. But it's probably more effective to do something you really like.

A UML component cannot contain UML package, that has no sense.
May be you confuse UML component and UML artifact ?
An UML artifact cannot contain an UML package, but the deployment of an UML package for Java is a directory so your Java tree of package / sub package / files can be supported by artifact with sub artifact if this is what you want to model.
(§19.3.1 from page 656 and §19.5.1 from page 660 in the norm )

Related

SAP Spartacus Translations

Is there a possibility disable SAP Spartacus I18next module in order to use my own translation module/strategy?
I'm trying to use my own shared module with translations but it is based on i18next library same as inspartacus/core, it seems like they are conflicting, because separately they work good.
It is possible but it would require a lot of work. I18nModule is a core part of the project and is imported in the StorefrontFoundationModule that is used in the in the StoreFrontModule and so on.
Therefore, to remove it would require to import all of the modules imported in the StorefrontFoundationModule, StoreFrontModule and B2cStorefrontModule. Directly to your AppModule. This is doable but the app is likely not to work.
Many components and services depend on translations so you would need to make sure your custom translation is provided in a way that it satisfies those dependencies.
Basically I am saying you are better of trying to extend or override the Spartacus translation functionalities to fit your use case. This module is configurable, extendable and powerful. Feel free too take a look at our documentation on the subject https://sap.github.io/cloud-commerce-spartacus-storefront-docs/i18n/#page-title.

Correct design using dependency inversion principle across modules?

I understand dependency inversion when working inside a single module, but I would like to also apply it when I have a cross-module dependency. In the following diagrams I have an existing application and I need to implement some new requirements for reference data services. I thought I will create a new jar (potentially a stand-alone service in the future). The first figure shows the normal way I have approached such things in the past. The referencedataservices jar has an interface which the app will use to invoke it.
The second figure shows my attempt to use DIP, the app now owns its abstraction so it is not subject to change just because the reference data service changes. This seems to be a wrong design though, because it creates a circular dependency. MyApp depends on referencedataservices jar, and referencedataservices jar depends on MyApp.
So the third figure gets back to the more normal dependency by creating an extra layer of abstraction. Am I right? Or is this really not what DIP was intended for? Interested in hearing about other approaches or advice.
,
The second example is on the right track by separating the implementation from its abstraction. To achieve modularity, a concrete class should not be in the same package (module) as its abstract interface.
The fault in the second example is that the client owns the abstraction, while the service owns the implementation. These two roles must be reversed: services own interfaces; clients own implementations. In this way, the service presents a contract (API) for the client to implement. The service guarantees interaction with any client that adheres to its API. In terms of dependency inversion, the client injects a dependency into the service.
Kirk K. is something of an authority on modularity in Java. He had a blog that eventually turned into a book on the subject. His blog seems to be missing at the moment, but I was able to find it in the Wayback Machine. I think you would be particularly interested in the four-part series titled Applied Modularity. In terms of other approaches or alternatives to DIP, take a look at Fun With Modules, which covers three of them.
In second approach that you presented, if you move RefDataSvc abstraction to separate package you break the cycle and referencedataservices package use only package with RefDataSvc abstraction.
Other code apart from Composition Root in MyApp package should depend also on RefDataSvc. In Composition Root of your application you should then compose all dependencies that are needed in your app.

Origin of hierarchical structuring

Why are libraries located behind com/ or net/ directory structures?
This is agnostic to Flash, Flex or any language. It's been used for a long time in general software development. I believe it stemmed from the Java package structure, but I'm not sure. It's used because it's now a standard on how to do things and helps split up projects in a fairly unique way.
It normally goes like <domain extension>/<domain>/<project name>/<sub component>/<whatever>.
This format/structure is called the reverse domain name structure. This structure is used for the package namespace for your classes.
Here is a good article on The Classpath Demystified by Jody Hall
If you're talking about class packages the point is every package should be unique. Imagine you wrote a class named MyGreatClass. Without any package or within some simple package test.MyGreatClass (this is called fully qualified class name). In this project you've decided to use some library where somebody wrote another test.MyGreatClass class (he/she didn't realize you have another one). So you'll have a conflict of two classes.
To avoid that situation there is a convention to start classes with author's site name in reverse order. Taking in mind every domain name is unique. Following this convention you can be sure you class won't conflict with others.
As far as com and net are most common domains you can see com.example (for http://example.com/) and net.example (for http://example.net/) very often.
Advantages of OOP
Inheritance
maintainability
Re-usability
A class is considered an object.
Having a package structure allows for all the advantages of OOP
Having a standard folder "com" where all your custom classes are allows you to reuse those classes with ease.
All libraries that I did not create, I make sure goes into my com folder. So when I make a new project I just have to point the project settings to that folder, then I can access those libraries with just having to do an import statement.
For example The AS3crypto library I have in the com folder.

Hiding Complexity by Building Concise Libraries

I'm developing a product with a bunch of interlocking pieces (server, client, libraries, etc) and one of the pieces is a tiny library that users will link into their own client-side code (something kind of like the Flickr API or the Google Maps API). Once they've included that library, all of the interlocking bits magically hook themselves together. So API simplicity is a major, important goal.
The API that I expose to users has a grand total of two classes and seven public methods. Easy peasy, lemon-squeezy.
But the simplicity is a carefully crafted illusion. The library I'm distributing actually depends on another library, with 136 classes of its own (and more than a thousand public methods). During the build process, I link the two libraries together into a single deliverable, for ease of integration and deployment by the API consumer.
The problem I'm facing now is that I don't want the end user (an application developer integrating my software to enhance their own functionality) to ever be bothered with all that extra cruft, drowning in a torrent of unnecessary complexity.
From the outside, the library should look like it contains exactly two public classes, with exactly seven public methods.
How do you handle this sort of thing in your own projects? I'm interested in the language agnostic solutions, as well as the various techniques for different languages, compilers, and build tools.
In my specific case, I'm developing for the flash platform (AIR/Flex/Actionscript) with SWC library files. The build methodology is analagous to the Java platform, where all classes are bundled into a zipped code module with equal visibility (an Actionscript SWC file is, conceptually, almost exactly identical to a Java JAR file).
Doesn't .NET have an "internal" modifier for classes and methods? That's exactly the sort of thing I'm looking for, and if anyone knows of a tricky technique to hide the visibility of classes between SWC boundaries, I'd love to hear it.
It's pretty hard to hide things in AS. There is an internal access specifier and there are also namespaces. Adobe has some help on Packages and namespaces that may be useful to you.
It is important to note that namespaces do not limit access - they are really used to place symbols into a different ... well namespace. This could be used to have 2 versions of the same library accessed in the same swf. My guess is it just does some name-mangling behind the scenes before inserting definitions into the symbol table. If users want, they can just import the namespace and access anything that is "hidden" behind it. I've done that when hacking apart Adobe components. That said, if the user doesn't have the original source and is incapable of determining the namespace identifier than you have a bit of security through obscurity.
package access specifiers (e.g. private and internal) are closer to what you want. But if you can access classes outside package boundaries then the user can too. There are even hacks I've seen around that can examine a swfc and spit out a list of embedded classes which one can use getClassByDefinition to instantiate.
So, you can hide the classes existence in your documentation, use internal and private access specifiers wherever possible and then use namespaces to mangle the classnames. But you cannot prevent a determined person from finding and using these classes.
I think you can pull this off by using namespaces:
http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000040.html
Notice that namespaces is not the same in actionscript as in C#, it is more like namespaces in xml.
Incidentally, one of the other tricks that I've used (since I didn't know about the "internal" modifier or namespaces) is to hide classes by declaring them outside the current package, like this:
package com.example {
public class A {
// ...
}
}
class B {
// ...
}
class C {
// ...
}
I've even though about writing a little tool that will analyze all the "import" directives within a project and move all external dependencies into these kinds of hidden private classes.

Actionscript 3.0: Scope

Tutorials usually don't deal with scope in Actionscript. Can you point me to some documentation and/or explain what should I know about it. I want to avoid problems arising from certain classes are not visible at certain places.
These should help.
Function scope:
http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_21.html
Packaging and namespace:
http://livedocs.adobe.com/flex/3/html/03_Language_and_Syntax_04.html#119303
You're a bit vague, but hopefully I'm getting you ;)
Scope for classes are generally pretty easy to handle, it mostly comes down to packages.
Packages are created in a simple tree structure, and in ActionScript3 the filestructre has to follow the namespaces. Which makes it even easier.
You can access any class from anywhere, but if it's in another package you will need to "import" the class. This is done by writing an import statement in the beginning of class or interface where you need to use it. Like so:
import flash.display.MovieClip;
There is an exception to this rule, a class can be declared with the internal keyword, in which case the class will only be available within that package. This is mostly used for helper classes.
Basicly you should not worry about classes not being available.
NB:
You create package with the package keyword.