Presenting fields in class diagram - language-agnostic

class A
{};
class B
{
A a;
};
When I want to present the above classes in class diagram I can do it like this:
Where I can present that class B has a field of class A either by marking it with a line ended with a rhombus (1 in the picture) or by specifying class's field (2 in the picture). However, using both seems redundant. When should I use the former, when the latter? Is there any case when I should use both?
Edit: Actually 1 could either be aggregation or composition. Although, the concrete line type isn't important to my question, IMO.
Edit2: I've found a more or less real-life example of diagram where this situation occurs: http://en.wikipedia.org/wiki/Decorator_pattern#mediaviewer/File:Decorator_UML_class_diagram.svg Class Decorator contains a field of type Component.

There is no rule in UML,
but there are best practices.
UML Best Practice: Attribute or Association says about that
Use Associations for Classes and Attributes for DataTypes

Related

Different types of class names in html

What is the diff bw
class="name"
class="name-new"
class="name new"
What is the difference bw the three and is there any other naming convention too?
The difference is that in case:
class="name": to the element will be applied only the properties of class "name"
class="name-new": like point one, but in this case the class is "name-new"
class="name new": in this case, to element will be applied two different classe: "name" and "new"
The "space" is used to separete multiple classes, same principle is used for the "id".
Also.. the syntax class="name-new" is not equal to use class="name_new".

How to comment out classes inside class=""? Is this even possible?

Is it possible to comment out specific classes inside the HTML (<div class="" ...>)?
For example:
<div data-group="group1" data-container="true" class="container-lg d-flex /* slider */ p-0">
Where in this example the class "slider" should be (temporarily) excluded from the class list.
[UPDATE]
Based on the comments I understand the way of thinking, so I go for the solution Lee Taylor mentioned. When I want to disable a specific class assignment, I just add a prefix to that class. For example:
<div class="slider container"...
becomes:
<div class="disable-slider container"...
Life could be so easy if the mind is thinking too complex :-D
Thank you all for thinking with me!
[/UPDATE]
This would make life a lot easier, in my opinion, in these ways:
You don't have to switch to your style sheet and go searching for the matching class, commenting out and switch back again to the code.
It's clear for everyone that you just exclude the complete function, which - if named clearly - gives other developers a better overview.
For testing purposes you could use this as (style) modules, which are enabled/disabled in a snap! Again, no more hopping between screens/tabs/windows.
Easier debugging. Just comment out some classes and you've got the source of the problem in no time.
It stimulates developers to use recognizable and clearly named classes
Currently I copy the whole element/row, comment this out and add a comment and then paste the copied row below. Then I remove classes from this line of code.
Most of the time this doesn't get updated, so you can't see it as a reliable backup if you're debugging.
I know for sure that such would be possible with JS, but why? (Also changing the HTML structure with JS gives a lot of headaches when it comes to layout shifts and not everyone has the possibility to make use of server side scripting.) Such should exist HTML in my opinion.
Am I the only one who has this in mind?
Per the HTML Specification on the class attribute:
When specified on HTML elements, the class attribute must have a value that is a set of space-separated tokens representing the various classes that the element belongs to.
Here is the definition for space-separated tokens:
A set of space-separated tokens is a string containing zero or more words (known as tokens) separated by one or more ASCII whitespace, where words consist of any string of one or more characters, none of which are ASCII whitespace.
A string containing a set of space-separated tokens may have leading or trailing ASCII whitespace.
Therefore, no, you should technically not be allowed to comment out class list members in any way. If any implementation of the specification does allow this, then it is undefined behavior and should not be depended upon.

How to select all elements with a specific name under every li node with the same structure?

I have a certain bunch of XPath locators that hold the elements I want to extract, and they have a similar structure:
/div/ul/li[1]/div/div[2]/a
/div/ul/li[2]/div/div[2]/a
/div/ul/li[3]/div/div[2]/a
...
They are actually simplified from Pixiv user page. Each /div/div[2]/a element has a title string, so they are actually artwork titles.
I want to use a single expression to fetch all the above a elements in an WebExtension called PageProbe. Although I've tried a bunch of methods, it just can't return the wanted result.
However, the following expression does return all the a elements, including the ones I don't need.
/div/
The following expression returns the a element under only the first li item.
/div/ul/li/div/div[2]/a
Sorry for not providing enough info earlier. Hope someone can help me out. Thanks.
According to the information you gave here you can simply use this xpath:
/div/ul/li/div/div[2]/a
however I'm quite sure it should be some better locator based on other attributes like class names etc.

How to edit this html lexer rule?

I want to edit this HTML lexer rule and I need help with the Regular Expression
the TAG_NAME refers to any HTML attribute for ex: (required, class, id, etc...).
I want to edit it to make it does not accept this exact syntax: 'az-'.
I think this needs regular expression modification, I looked it up but I couldn't integrate what I found online with the way these rules are written.
I tried to remove the '-' in the Tag_NameChar as a first try but that made the HTML doesnt recognize attributes like 'data-target'.
This snippet is for the rule:
and this one shows how the attributes are recognized.
ANTLR does not support lookahead syntax like some regex engines do, so there's no easy way to exclude certain matches from within the regex. It's always possible to rewrite a regular expression to exclude a given string (regular expressions are closed under negation and intersection), but it usually ends up quite painful. In your case, you'd end up with something following the logic of "a tag name can either have less than 3 characters, more than 3 characters, or it could have three characters where the first isn't an 'a', the second isn't a 'z' or the last isn't a '-'".
The less painful, but also less cross-language solution is to use a predicate that returns false if the text of the tag name equals az-. So something like {getText().equals("az-")}? depending on the language.
If you're okay with introducing an additional lexer rule, you may also introduce a rule INVALID_TAG_NAME (or whatever you want to call it) that matches exactly az- and that's defined before TAG_NAME. That way any tag that's named exactly az- will produce an INVALID_TAG_NAME token instead of a TAG_NAME token.
Depending on your requirements, you could also leave the grammar unchanged altogether and simply produce an error when you see a tag named az- when you traverse the tree in a listener or visitor.

attribute selector for class starts with and ends with

I have been reading up on attribute selectors, such as ~ ^ | etc, but I cant figure out the following:
How do I target an element with a class starting with lets say "abc" and also ends with "xyz".
The way I have it now is this:
div[class^="abc"][class$="xyz"]{}
But if my element looks like this, it wont work:
<div class="foo abcDExyz bar">
It only works if abcDExyz is the only class in the class attribute.
Basically, I want to target a class that starts with something... and ends with something. In between that, anything can go (such as 'DE' in my example)
Is my only option to use * instead?
thanks in advance!
You can only do this if you can guarantee that the substrings "abc" and "xyz" will never appear in any other class names within that element's class attribute, and they will never appear separately:
div[class*=" abc"][class*="xyz "]
And even this falls flat when that class name is the first, last, or only one in the class attribute (unless you include the respective ^= and $= attribute selectors, but it's all still very fragile).
Otherwise, you won't be able to do this reliably with just a selector, or even a list of selectors.
You'd have a much easier time if whatever "abc" and "xyz" are supposed to represent was its own class name, instead...