Difference between dependency and import/access in package diagram - oop

I thought import and access are types of dependency, but there was a site saying that they're not. It says that the dependency is a little it different with the import/access relationship.
What are the differences? Thanks in advance.

Dependency
A Dependency implies that the semantics of the clients are not complete without the suppliers. The presence of
Dependency relationships in a model does not have any runtime semantic implications. The semantics are all given in
terms of the NamedElements that participate in the relationship, not in terms of their instances.
PackageImport
A PackageImport is a DirectedRelationship between an importing Namespace and a Package, indicating that the
importing Namespace adds the names of the members of the Package to its own Namespace.
PackageMerge
A PackageMerge is a directed relationship between two Packages that indicates that the contents of the target
mergedPackage are combined into the source receivingPackage according to a set of rules defined below. It is very similar
to Generalization in the sense that the source element conceptually adds the characteristics of the target element to its
own characteristics resulting in an element that combines the characteristics of both.
Dependency states that it doesn't have any runtime semantic implications; that must remain true for all subclasses (subclass cannot relax constraints). So if the PackageImport was a subclass of Dependency, then it wouldn't be able to import anything.
To oversimplify: Dependency captures an idea (e.g. this package «use»s this other package, but we don't care how), whilst PackageImport captures an action (e.g. this package «import»s this other package with these precise mechanics).
As a sidenote, they do share a common ancestor in the form of DirectedRelationship

Related

What does dependency/dependant mean?

http://tutorials.jenkov.com/ood/understanding-dependencies.html#whatis says that (emphasis mine):
Whenever a class A uses another class or interface B, then A depends on B. A cannot carry out it's work without B, and A cannot be
reused without also reusing B. In such a situation the class A is
called the "dependant" and the class or interface B is called the
"dependency". A dependant depends on its dependencies.
According to Google's definition:
a dependent or subordinate thing, especially a country or province
controlled by another.
Since A depends on B, the dependency is A and the dependant is B. This is contrary to the first quote. Or am I missing something?
Terminology is context dependent. In general, the dependency is a synonym of dependence and describes not one entity, but state. According to Cambridge dictionary:
the situation in which you need something or someone all the time, especially in order to continue existing or operating.
So it's more about a relation to something. For example:
A minor child is dependent of his/her parents. The child is in a state
of dependency. The dependency describes the relation between the child and its parents.
The google definition is only one of the available definitions (see for example the Collins dictionary), the one that is especially applicable in the context of geopolitics and real estate. For example:
Before 1776, America was a dependency of the British Empire. The
dependency America was dependent on the Empire.
He bought a farm with several dependencies
The object oriented terminology is not so different from the more general definition: a dependency is a relationship between objects or classes. Here a more formal definition from the UML 2.5 standard:
7.7.1: A Dependency signifies a supplier/client relationship between model
elements where the modification of a supplier may impact the client
model elements.
So, restating what's in the tutorial, we can say that:
If A has to use B, A depends on B. There is a relation of dependency
from A to B. A is said to be the dependent.
For practical reason and language convenience, B is often called the dependency (which is indeed the contrary of everyday's language). But in reality, it is still the relation of A to B that is the dependency.
The thing that is dependent on something is the dependency. I am dependent on H. I need H injected into me. H is a dependency of me.

Analyzer dependencies from class in IDEA or in another java tool

I'm looking the way to understand full influence of changing some class. For example I added new field to DTO class. It is needed to find all web-services and methods that are affected by this change. For a now I need to find all classes that extend changed class, all classes that aggregate this class or any of its children, all classes that use type of changed class or of its children, etc. Risk to lose affected web-services is very high. And if I lose even one web-services it means bug during integration process.
Is there tool that makes this process automatic?
It sounds like you want to use the Dependency Matrix, which is available under the Analyze menu from the action Analyze Dependency Matrix. This shows you efferent and afferent dependencies, along with metrics that can be used to infer the strength of the dependency.

How does the organisation of classes in categories and packages work in different versions of Pharo?

Can someone explain how the organisation of classes in Pharo works in different versions of Pharo?
All Classes are part of the Smalltalk global (have always been, seem to stay like this?)
Classes can have a Category, but thats only a kind of tag? (has always been, seems to stay like this? But the categories are somehow mapped to packages sometimes?)
There are different kinds of Packages in different Versions of Pharo
MCPackages representing Monticello Packages
PackageInfo
RPackage (Pharo 1.4)?
In addition there is SystemNavigation which somehow helps navigating classes and methods based on some of the above mentioned constructs?
Classes
The fact that classes are keys in the Smalltalk global is an implementation detail. As long as there is a single global namespace for class names, it is likely that the implementation will stay the same.
Class Categories
The class category is very much like a tag. A class can only be in one category at a time. Originally the class category was used by the Browser for organizing the classes in the system.
When Monticello was created, the class category was overloaded to also indicate membership in a Monticello package theMCPackage and PackageInfo classes were created to manage this mapping.
PackageInfo does all the heavy lifting: finding the classes and loose methods that belong to a package.
MCPackage is a Monticello-specific wrapper for PackageInfo that adds some protocol that wasn't necessarily appropriate for the more general PackageInfo.
Packages
Overloading the class category for package membership was a neat trick to ease the adoption of Monticello (existing development tools didn't need to be taught Monticello), however, it is still a trick. Not to mention the fact that the implementation of PackageInfo was not very efficient.
RPackage was created to address the performance problems of PackageInfo and to be used as part of the next generation of development tools.
Both package implementations will continue to exist until PackageInfo can be phased out.
SystemNavigation
As Frank says,
SystemNavigation is a class that, as its name suggests, permits easy
querying of a number of different things: the classes in the image,
senders-of, implementors-of, information about packages loaded in the
image and so on.
Classes are, at the moment at least, the keys in the Smalltalk dictionary.
PackageInfo contains information about a grouping of classes and extensions to other packages.
A Monticello package contains a deployable unit of code. Usually one of these will correspond to a PackageInfo instance. (Hitting the "+Package" button in a Monticello Browser will create one of these, for instance.) A Monticello package may contain pre-load and post-load scripts, so the two classes perform separate, if related, functions.
SystemNavigation is a class that, as its name suggests, permits easy querying of a number of different things: the classes in the image, senders-of, implementors-of, information about packages loaded in the image and so on.

When exactly does a class/package depend on another?

Many articles/books/.... talk about class or package dependency, few explain what it is. I did find some definitions, but they vary and probably don't cover all cases. E.g.:
"when one class uses another concrete class within its implementation" (so there exists no dependency on an interface?)
"when a class uses another as a variable" (what about inheritance?)
"if changes to the definition of one element may cause changes to the other" (so dependency is a transitive relationship not just on packages, but also on class level?)
"the degree to which each program module relies on each one of the other modules" (but how do you define "relies"?)
Further aspects to consider are method parameters, dependency injection, aspect oriented programming, generics. Any more aspects?
So, can you give a (formal) definition for dependency amongst classes and amongst packages that is fool-proof and covers all these cases and aspects?
If you are asking for dependency in the context of inversion of control or dependency injection, well, you're probably interested in classes that interact with one another directly. That means mostly constructor parameters and properties.
In the context of a UML domain diagram, you're probably interested in "real world" dependency. A dog needs food. That's a dependency. The dog's Bark() method returns a Sound object: that's not something you're interested in, in a UML domain model. The dog doesn't depend on sounds to exist.
You could go philosophical on this also: All classes depend on each other to accomplish a common goal; a (hopefully) great software.
So, all in all, dependency or coupling is not a matter of yes or no. It really depends on the context and on a degree of coupling (weak, strong). I thinks that explains why there are some many divergent definition of dependency.
I wrote a blog post on that topic a while ago: Understanding Code: Static vs Dynamic Dependencies. Basically you need to make a difference between static dependencies, those that are resolved by the compiler at compile-time, and dynamic dependencies, those that are resolved by the runtime (JVM or CLR) at run-time.
static dependencies are typically provoked by calls to static/final methods, read/write to a field, in the definition of the class C the implementation of the interface I by C ... all these associations between code elements that can be found explicitly in the bytecode and source code.
dynamic dependencies are typically provoked by everything that abstracts a method call at compile time, like calls to abstract/virtual methods (polymorphism), variables or parameters typed with an interface (the implementation class is abstracted at compile-time), but also delegates (.NET) or pointers to function (C++).
Most of the time, when you'll read about dependencies in the literature, they are talking about static dependencies.
A static dependencies is direct (meaning not transitive). A tool like NDepend that I mention in the blog post, can also infer indirect (or call it transitive) static dependencies from the set of direct static dependencies.
The idea I defend in the blog post is that when it comes to understand and maintain a program, one needs to focus mostly on the static dependencies, the ones found in the source code.. Indeed, abstractions facilities are used to, well ... abstract, implementation for callers. This makes source code much more easy to develop and maintain. There are however situations, typically at debugging time, where one needs to know what's really behind an abstraction at run-time.
This post is about static dependency - for dynamic dependency and the difference, see
Patrick Smacchia's answer.
In an easy to understand way: an entity (class or package) A depends on an entity B when A cannot be used standalone without B.
Inheritance, aggregation, composition, all of them introduces dependency between related entities.
so there exists no dependency on an interface?
there is, but interface only serves as the glue.
what about inheritance?
see above.
so dependency is a transitive relationship not just on packages, but also on class level?
yep.
but how do you define "relies"?
see above "easy to understand" definition. also related to the 3rd definition you posted.
Update:
So if you have interface A in Package P1, and class C in Package P2 uses A as
method parameter, or
local variable woven into C via AOP, or
class C implements A, or
class C<E extends A>,
then C depends on A and P2 depends on P1.
But if interface A is implemented by class B and class C programs against the interface A and only uses B via dependency injection, then C still (statically!) only depends on A, not on B, because the point of dependency injection is that it doesn't make glued components dependent.

Terminology: What's the difference between a class and a component?

Within the OO paradigm, we choose to use classes because they help us to break the system down, and provide nice side benefits such as encapsulation, separation of responsibilities, inheritance, modularity, etc.
If we look at a software system at the component level, can we simply treat components in the same conceptual way, i.e. a component is simply a "Big Class"? Or is there more to it than that?
What extra considerations must be given when designing components?
EDIT:
I know that a class and a component are different things. I also understand that a component may contain many many classes, each of which have their own roles and responsibilities.
I'll see if I can explain myself better.
Classes allow us to solve bigger problems because they allow us to think and design more abstractly.
There are rules & techniques to determine how to break down and assign data and functionality to classes.
This seems like a very similar situation to that of component design, just at a higher level of abstraction. Do the techniques used to determine what classes are needed scale up to components, and/or are there other things that affect a high-level system design that don't apply at the class abstraction level?
what about using the project phase or role to differentiate them?
For example a component is a design-time unit (system architects, designers) whereas a class is an implementation-time unit (programmers). So designers speak about components (or subsystems or modules, the hight-level boxes in your architecture drawing) whereas programmer speak about components and classes (that implements components).
Under this view a component is implemented by one or more classes.
I often think of Component in the UML sense (see Wikipedia description), whereby it represents a "modular part of a system". In this sense it tends to represent a larger piece of functionality than a class and could in fact be composed from multiple classes.
Considerations I would give to designing components are:
How it could be re-used. In particular what are the use cases that warrant implementing something as a component rather than bespoke code (As a grad I used to make everything re-useable!)
Providing sensible interface(s), and in some cases additional simplified interfaces, perhaps using the Facade pattern.
Hope that helps.
In this (hypothethical) context a component can be thought of as a series of classes.
However depending on the technology you use, components can be more then a set of classes.
i.e. They may have additional properties and functionality which is not part of the classes which form them.
e.g. a COM+ component.
So it depends on a specific situation really.
According the UML v2 specification:
8.3.1 Component (from BasicComponents, PackagingComponents)
A component
represents a modular part of a system
that encapsulates its contents and
whose manifestation is replaceable
within its environment.
A component
defines its behavior in terms of
provided and required interfaces. As
such, a component serves as a type
whose conformance is defined by these
provided and required interfaces
(encompassing both their static as
well as dynamic semantics). One
component may therefore be substituted
by another only if the two are type
conformant. Larger pieces of a
system’s functionality may be
assembled by reusing components as
parts in an encompassing component or
assembly of components, and wiring
together their required and provided
interfaces.
When you use this definition, components appear to be all about Inversion Of Control.
Looking at the .NET framework for an example, the IComponent interface indeed provides IComponent.Site.GetService to achieve inversion of control through the service provider pattern. A more light-weight alternative is dependency injection.
Eh?
The "File Uploading" component may consist of lots of classes: Page to receive the file, class to save it, etc.
components are subsystems of classes.Classes provide the basic low level blueprint of an object interface while components adds some functionality to it.