Is the target of 3 dependencies per class always achievable?


I’m reading the Clean Code book and a chapter says that if a class has more than 3 dependencies is a code smell of that class isn’t doing one thing. Or what is the same, it isn’t following SRP. I’m thinking in certain scenarios in which I am unable to reset the number of dependencies to stick to that number.

Let’s say we have an app that connects to a public API REST what offers varied information about a lot entities in our domain. In our app we detect an use case repeated in many places where we request to the API the info about an entity with other dependent entities that it has.

The API REST doesn’t offer the data in the format we want because the calls when can make are to get data from a single table on the web database, not offers the data agrouped with other tables as we want. So our use case have to make different Api Call’s for to get all different data about the entities we need and then merge in the model we will use in the app.

To connect with the external subsystem we will hide implementation in a single Service class however this class has grown too much resulting a class with a lot methods to get data about all entities of the api rest. So we split this huge class into differents following the Repository pattern. Each class for each possible operations with an entity on the API.

Then, to hide all this concrete and common interaction with the service layer we will use a Facade class to coordinating all this calls. The problem I’m figuring it will have, is that it will have a lot dependencies in her constructor. Will have classes for each repository class and mapper classes to adapt the web data into app data.

The solution in these cases is merge all related dependencies in one so you reduce the number. One example is this: Refactoring to Aggregate Services. http://blog.ploeh.dk/2010/02/02/RefactoringtoAggregateServices/

But you merge when you see a clear relationship. What happend if in your class you can’t see that? All classes are granulated but all of them are necesary to achieve the goal but can’t not be merged in an aggregate service.

So my question is, the “rule” that more than three dependencies violates SRP is always applicable? Returning to our example, our facade needs to access many repository classes and mapper classes. The mapper classes can be hide on a agreggated service, maybe, but repository classes are fine like are. We could introduce a service locator to store them but it is a very bad practice.

If A and B are candidate keys, then AB is candidate key or not ?


If R{abc} is a relation, f{ a->b b->a a->c b->c }, then a and b are candidate keys. What about ab ? Is it a candidate key or is it a super key or both ?

How to model the dependencies between fields in very complex forms


We have to create a web application that will be used as an application form for multiple insurance products (15 in total). This application form will be similar to a form wizard, it will span across multiple pages, depending on what product between 4 and 10.

The grand total of all different elements (inputs, select boxes) that the form will be rendering is around 250, but even the most complex product will not use more than 170 of them. The least complex one still requires around 80 elements.

We do not want to create 15 different application forms, one per product, we want to have a single application form which will be used by all products.

Now as you can imagine, the elements have a lot of dependencies between them. A value entered in a field can make another field or set of field appear or disappear (on the current page or a following page(s)). Some other dependencies based on entered values:

  • value of an element is required or not
  • possible values for select boxes will be changed
  • the validation constraints will be changed

As you can imagine, modeling this is very complex. The question is, what tool would you recommend for modeling (and documenting) all these elements, the dependencies between them and the validation constraints? How would you do the modeling? Not talking about the data model at all in this case. This model will be part of the specifications of what needs to be done and as a reference after the completion of the project. By changing the model the application forms will not be automatically changed.

Some of the things we would like to be able to do easily:

  • see what elements a certain element depends on
  • see all elements included in the form for certain product
  • see required elements for a certain product
  • define validation rules for each element
  • define various attributes for each element

Limitation: our product managers and product owners are the ones who will do the modelling.

How to manage coupling in model classes


I’m doing a class diagram for a game project, but I’m stuck on a coupling problem.

Context

The projet is a turn-based game. Two users are playing. They’ve got units on a map. They play until 1 player has all his units dead or if a predefined number of turns are reached.
At each round, each player will review his units one by one:

  • he can move an unit until the unit hasn’t got any movement point left
  • he can skip the unit’s turn

Modeling

Class diagram

Classes irrelevant to the questions have been cut

The Game class holds all the relevant objects : the players, the units, the current turn (which player(s) have already played, who’s next, …). The Turn object holds a PlayerTurn object, which keeps tracks of which units have already been played, which units are left to play, …

Problem

-> Let’s suppose we’re creating the GetNextPlayableUnit method (in class PlayerTurn).

We’ll have to iterate through the current player’s units and find one that is not in the “PlayedUnits” list. Therefore, we’ll have to call Game.Units.GetUnits with the parameter Game.Turn.CurrentPlayer (Game refers to the current Game’s instance).

-> Let’s suppose we’re creating the MoveTo method (in class Unit).

If the Unit hasn’t got any movement point left, we’ll have to call Game.Turn.PlayerTurn.Finish which will either select the next playable unit or finish the current player’s turn if he already played all of his units this turn.

-> … There are a lot of other scenarios where we’ll need to access other classes’ method. E.g., a “Kill” method on Unit will have to check if the current player has still got at least 1 unit alive, and it will have to call a Finish method on Game otherwise.

Question

I think the coupling can’t be avoided (correct me if I’m wrong though!). I’ve thought about two possible ways of dealing with coupling:

Solution 1

When constructing instances of these classes, I could pass the current Game’s instance. After all, it makes sense: Unit instances, Turn instances, … all belong to a game.
Then, I could implement the methods GetNextPlayableUnit, MoveTo, Killed, … easily by using this instance. Somehow, I don’t feel comfortable sharing the current game’s instance between all the model classes, even though I read here and there that it was the principle of dependency injection.

Solution 2

  1. Analyse the method dependencies: e.g., Kill method depends on Game.Units.Unit.Player (to retrieve the Player owning the Unit), on Game.Units.GetUnits (to find all other Units owned by the player), on Game.End to end the game if unit count of the player has reached 0.
  2. Find the dependencies common root: in the example above, the common root between Game.Units.Unit, Game.Units and Game is Game. In another example, if we had the dependencies Game.Units.Unit & Game.Units.SomethingElse, the common root would be Game.Units.
  3. Implement the method in this common root class. We’re guaranteed not to need to access parent classes (in the association hierarchy).

Risks:

  • lots of methods will have the Game class for common root => lots of methods in Game class => lots of code in Game class.
  • methods won’t belong to their rightful classes. Consider the method “KillUnit”: you’d expect to find it in the Unit class directly, not in the Game class. Same goes for “MoveTo”, “Finish”, …

Is there any other solution you can think of? What would be the best approach in this particular case?

Trying to install rpm package in Fedora 21, but dependency on OpenJDK 7 results in errors


I am running Fedora 21 32bit workstation version.

Trying to install iris-4.22.0-1.noarch.rpm:

[itse@localhost Downloads]$ sudo yum install iris-4.22.0-1.noarch.rpm
[sudo] password for itse: 
Loaded plugins: langpacks
Examining iris-4.22.0-1.noarch.rpm: iris-4.22.0-1.noarch
Marking iris-4.22.0-1.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package iris.noarch 0:4.22.0-1 will be installed
--> Processing Dependency: java-1.7.0-openjdk for package: iris-4.22.0-1.noarch
--> Processing Dependency: postgresql-jdbc for package: iris-4.22.0-1.noarch
--> Processing Dependency: postgresql-server for package: iris-4.22.0-1.noarch
--> Running transaction check
---> Package iris.noarch 0:4.22.0-1 will be installed
--> Processing Dependency: java-1.7.0-openjdk for package: iris-4.22.0-1.noarch
---> Package postgresql-jdbc.noarch 0:9.3.1102-1.fc21 will be installed
---> Package postgresql-server.i686 0:9.3.5-5.fc21 will be installed
--> Processing Dependency: postgresql-libs(x86-32) = 9.3.5-5.fc21 for package: postgresql-server-9.3.5-5.fc21.i686
--> Processing Dependency: postgresql(x86-32) = 9.3.5-5.fc21 for package: postgresql-server-9.3.5-5.fc21.i686
--> Processing Dependency: libpq.so.5 for package: postgresql-server-9.3.5-5.fc21.i686
--> Running transaction check
---> Package iris.noarch 0:4.22.0-1 will be installed
--> Processing Dependency: java-1.7.0-openjdk for package: iris-4.22.0-1.noarch
---> Package postgresql.i686 0:9.3.5-5.fc21 will be installed
---> Package postgresql-libs.i686 0:9.3.5-5.fc21 will be installed
--> Finished Dependency Resolution
Error: Package: iris-4.22.0-1.noarch (/iris-4.22.0-1.noarch)
           Requires: java-1.7.0-openjdk
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

The error states a dependency on java-1.7.0-openjdk, but as I understand Fedora 21 uses java-1.8.0-openjdk.

How do I overcome this dependency? As I understand packages dependent on OpenJDK 7, should be able to also work on OpenJDK 8.

I tried to manually install the OpenJDK7 rpm downloaded from this link: http://rpmfind.net//linux/RPM/fedora/updates/20/i386/java-1.7.0-openjdk-1.7.0.75-2.5.4.2.fc20.i686.html

The installation failed with the following error:

[itse@localhost Downloads]$ sudo yum install java-1.7.0-openjdk-1.7.0.75-2.5.4.2.fc20.i686.rpm
[sudo] password for itse: 
Loaded plugins: langpacks
Examining java-1.7.0-openjdk-1.7.0.75-2.5.4.2.fc20.i686.rpm: 1:java-1.7.0-openjdk-1.7.0.75-2.5.4.2.fc20.i686
Marking java-1.7.0-openjdk-1.7.0.75-2.5.4.2.fc20.i686.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package java-1.7.0-openjdk.i686 1:1.7.0.75-2.5.4.2.fc20 will be installed
--> Processing Dependency: java-1.7.0-openjdk-headless = 1:1.7.0.75-2.5.4.2.fc20 for package: 1:java-1.7.0-openjdk-1.7.0.75-2.5.4.2.fc20.i686
--> Processing Dependency: xorg-x11-fonts-Type1 for package: 1:java-1.7.0-openjdk-1.7.0.75-2.5.4.2.fc20.i686
--> Running transaction check
---> Package java-1.7.0-openjdk.i686 1:1.7.0.75-2.5.4.2.fc20 will be installed
--> Processing Dependency: java-1.7.0-openjdk-headless = 1:1.7.0.75-2.5.4.2.fc20 for package: 1:java-1.7.0-openjdk-1.7.0.75-2.5.4.2.fc20.i686
---> Package xorg-x11-fonts-Type1.noarch 0:7.5-14.fc21 will be installed
--> Processing Dependency: ttmkfdir for package: xorg-x11-fonts-Type1-7.5-14.fc21.noarch
--> Processing Dependency: ttmkfdir for package: xorg-x11-fonts-Type1-7.5-14.fc21.noarch
--> Running transaction check
---> Package java-1.7.0-openjdk.i686 1:1.7.0.75-2.5.4.2.fc20 will be installed
--> Processing Dependency: java-1.7.0-openjdk-headless = 1:1.7.0.75-2.5.4.2.fc20 for package: 1:java-1.7.0-openjdk-1.7.0.75-2.5.4.2.fc20.i686
---> Package ttmkfdir.i686 0:3.0.9-44.fc21 will be installed
--> Finished Dependency Resolution
Error: Package: 1:java-1.7.0-openjdk-1.7.0.75-2.5.4.2.fc20.i686 (/java-1.7.0-openjdk-1.7.0.75-2.5.4.2.fc20.i686)
           Requires: java-1.7.0-openjdk-headless = 1:1.7.0.75-2.5.4.2.fc20
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

Can I just install OpenJDK 8 and somehow remove the dependency on OpenJDK 7 since 8 is backwards compatible with 7?

Non-sense error messages for unmet dependencies in Debian Jessie


My problem is not understanding the error messages: It says I need blah-blah-1.49 (>= 1.49-1) and this is not installable but I have blah-blah-1.55 installed already.

I think 1.55 is greater than or equal to 1.49.

Is this the correct way to use Bower


I’m using Bower whereby I run bower install and it downloads dependency files to /bower_components directory. Then, I create symlinks from my /public/.. directories to the dist files:

mypc:/var/www/myproject/public/js$ ls -l
total 8
lrwxrwxrwx 1 tom tom   67 Dec 23 07:29 bootstrap.min.js -> /var/www/myproject/bower_components/bootstrap/dist/js/bootstrap.min.js
lrwxrwxrwx 1 tom tom   58 Dec 23 07:29 jquery.min.js -> /var/www/myproject/bower_components/jquery/dist/jquery.min.js

Is this the way that Bower is typically used? I’m trying to find a way to automate the process, the best I’ve thought is to exec a install.sh after installation but was wondering if this can be done with Bower. Is there a better/preferred way? I thought against putting the bower_components in the public directory too as there are lots of files that don’t need to be there (e.g. README, src, etc). In most cases I only require one or two files from each.

Unmet dependency after linux mint distribution update


I have recently updated to Linux mint rebecca. I am getting unmet dependencies for apt-get

when I am trying to apt-get install a package named monodevelop-nunit monodoc-nunit-manual then this happens.

sudo apt-get install monodevelop-nunit monodoc-nunit-manual
Reading package lists... Done
Building dependency tree       
Reading state information... Done
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
 mint-mdm-themes : Depends: mint-mdm-themes-html but it is not going to be installed
 monodevelop-nunit : Depends: libnunit-core-interfaces2.6.3-cil but it is not going to be installed
                     Depends: libnunit-core2.6.3-cil but it is not going to be installed
                     Depends: libnunit-framework2.6.3-cil but it is not going to be installed
                     Depends: libnunit-util2.6.3-cil but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

then I do this

 apt-get -f install  
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following extra packages will be installed:
  mint-mdm-themes-html
The following NEW packages will be installed:
  mint-mdm-themes-html
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
6 not fully installed or removed.
Need to get 0 B/15.8 MB of archives.
After this operation, 24.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 438154 files and directories currently installed.)
Preparing to unpack .../mint-mdm-themes-html_1.8.3_all.deb ...
Unpacking mint-mdm-themes-html (1.8.3) ...
dpkg: error processing archive /var/cache/apt/archives/mint-mdm-themes-html_1.8.3_all.deb (--unpack):
 trying to overwrite '/usr/share/mdm/html-themes/SpaceRace/ship3.png', which is also in package mdm-html5-themes-samriggs 0.1.3~debian+dmdc
dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/mint-mdm-themes-html_1.8.3_all.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

then

apt-cache policy mint-mdm-themes-html
mint-mdm-themes-html:
  Installed: (none)
  Candidate: 1.8.3
  Version table:
     1.8.3 0
        700 http://packages.linuxmint.com/ rebecca/main i386 Packages

my source.list is like this

 cat /etc/apt/sources.list
 # deb http://apt.jenslody.de/ any main
  # deb-src http://apt.jenslody.de/ any main
#deb cdrom:[Linux Mint 16 _petra_ - Release i386 20131126]/ saucy contrib main non-free   deb http://apt.wxwidgets.org/ squeeze-wx main

how can I resolve it?

calculating Canonical covers


Given F = {AB -> C, A -> BC, B-> A}, compute Fc

AB-> C is A extra?
{B->C, A-> BC, B->A}
1st possible Fc = {A->BC, B->AC}

AB-> C is B extra?

{A->C, A->BC, B->A)

2nd possible Fc = {A->BC, B->A)

Am I calculating the Fc correctly. I feel like I am doing something wrong?

How to maintain and import self-made libraries


Over the years I’ve written some libraries. These libraries sometimes depend on each other.

As a result, the “tex” directory is structured as follows:

tex
├── library
|   ├── library1.sty
|   ├── library2.sty
|   └── library3.sty
├── project1
|   ├── master.tex
|   ├── chapter1.tex
|   └── chapter2.tex
├── project2
|   └── article.tex
└── project3
    └── paper.tex

The libraries depend on each other. As a result, in every library that depends on another library, this is part of the header:

%library2.sty
ProvidesPackage{library2}
RequirePackage{../library/library1}

In other words, the library is imported from the “root of every project”. This is not a good design choice. What if someone copies the libraries in the folder of the root of a project, or what if the folder “library” is renamed…

It is however reasonable the “active directory” still remains in the project root.

What can be done to resolve such library dependencies?

Question and Answer is proudly powered by WordPress.
Theme "The Fundamentals of Graphic Design" by Arjuna
Icons by FamFamFam