Skip to content

Commit 25fc787

Browse files
committed
correct 2&3 and 3 only.
1 parent d217d8c commit 25fc787

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

_overviews/scala3-book/domain-modeling-tools.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ If you want them to be immutable---read only---create them as `val` fields inste
4646

4747
Prior to Scala 3, you used the `new` keyword to create a new instance of a class:
4848

49-
{% tabs class_2 class=tabs-scala-version %}
49+
{% tabs class_2 %}
5050
{% tab 'Scala 2 and 3' for=class_2 %}
5151

5252
```scala
@@ -59,7 +59,7 @@ val p = new Person("Robert Allen Zimmerman", "Harmonica Player")
5959

6060
However, with [creator applications][creator] this isn’t required in Scala 3:
6161

62-
{% tabs class_3 class=tabs-scala-version %}
62+
{% tabs class_3 %}
6363
{% tab 'Scala 2 and 3' for=class_3 %}
6464

6565
```scala
@@ -71,7 +71,7 @@ val p = Person("Robert Allen Zimmerman", "Harmonica Player")
7171

7272
Once you have an instance of a class such as `p`, you can access its fields, which in this example are all constructor parameters:
7373

74-
{% tabs class_4 class=tabs-scala-version %}
74+
{% tabs class_4 %}
7575
{% tab 'Scala 2 and 3' for=class_4 %}
7676

7777
```scala
@@ -84,7 +84,7 @@ p.vocation // "Harmonica Player"
8484

8585
As mentioned, all of these parameters were created as `var` fields, so you can also mutate them:
8686

87-
{% tabs class_5 class=tabs-scala-version %}
87+
{% tabs class_5 %}
8888
{% tab 'Scala 2 and 3' for=class_5 %}
8989

9090
```scala
@@ -184,7 +184,7 @@ class Socket(val timeout: Int = 5_000, val linger: Int = 5_000):
184184

185185
A great thing about this feature is that it lets consumers of your code create classes in a variety of different ways, as though the class had alternate constructors:
186186

187-
{% tabs default-values_2 class=tabs-scala-version %}
187+
{% tabs default-values_2 %}
188188
{% tab 'Scala 2 and 3' for=default-values_2 %}
189189

190190
```scala
@@ -201,7 +201,7 @@ val s = Socket(linger = 10_000) // timeout: 5000, linger: 10000
201201
When creating a new instance of a class, you can also use named parameters.
202202
This is particularly helpful when many of the parameters have the same type, as shown in this comparison:
203203

204-
{% tabs default-values_3 class=tabs-scala-version %}
204+
{% tabs default-values_3 %}
205205
{% tab 'Scala 2 and 3' for=default-values_3 %}
206206

207207
```scala
@@ -325,7 +325,7 @@ The class has three constructors, given by the numbered comments in the code:
325325

326326
Those constructors can be called like this:
327327

328-
{% tabs structor_2 class=tabs-scala-version %}
328+
{% tabs structor_2 %}
329329
{% tab 'Scala 2 and 3' for=structor_2 %}
330330

331331
```scala
@@ -376,7 +376,7 @@ object StringUtils:
376376

377377
We can use the object as follows:
378378

379-
{% tabs object_2 class=tabs-scala-version %}
379+
{% tabs object_2 %}
380380
{% tab 'Scala 2 and 3' for=object_2 %}
381381

382382
```scala
@@ -414,7 +414,7 @@ isNullOrEmpty("John Casey") // false
414414

415415
or just _some_ members:
416416

417-
{% tabs object_4 class=tabs-scala-version %}
417+
{% tabs object_4 %}
418418
{% tab 'Scala 2 and 3' for=object_4 %}
419419

420420
```scala
@@ -716,7 +716,7 @@ class IrishSetter(name: String) extends HasLegs, HasTail:
716716
Notice that the `IrishSetter` class implements the abstract members that are defined in `HasLegs` and `HasTail`.
717717
Now you can create new `IrishSetter` instances:
718718

719-
{% tabs traits_5 class=tabs-scala-version %}
719+
{% tabs traits_5 %}
720720
{% tab 'Scala 2 and 3' for=traits_5 %}
721721

722722
```scala
@@ -835,7 +835,7 @@ Basic enumerations are used to define sets of constants, like the months in a ye
835835

836836
As an example, these enumerations define sets of attributes related to pizzas:
837837

838-
{% tabs enum_1 class=tabs-scala-version %}
838+
{% tabs enum_1 %}
839839
{% tab 'Scala 3 only' for=enum_1 %}
840840

841841
```scala
@@ -854,7 +854,7 @@ enum Topping:
854854

855855
To use them in other code, first import them, and then use them:
856856

857-
{% tabs enum_2 class=tabs-scala-version %}
857+
{% tabs enum_2 %}
858858
{% tab 'Scala 3 only' for=enum_2 %}
859859

860860
```scala
@@ -867,7 +867,7 @@ val currentCrustSize = Small
867867

868868
Enum values can be compared using equals (`==`), and also enum_1ed on:
869869

870-
{% tabs enum_3 class=tabs-scala-version %}
870+
{% tabs enum_3 %}
871871
{% tab 'Scala 3 only' for=enum_3 %}
872872

873873
```scala
@@ -889,7 +889,7 @@ currentCrustSize enum_1
889889

890890
Enumerations can also be parameterized:
891891

892-
{% tabs enum_4 class=tabs-scala-version %}
892+
{% tabs enum_4 %}
893893
{% tab 'Scala 3 only' for=enum_4 %}
894894

895895
```scala
@@ -904,7 +904,7 @@ enum Color(val rgb: Int):
904904

905905
And they can also have members (like fields and methods):
906906

907-
{% tabs enum_5 class=tabs-scala-version %}
907+
{% tabs enum_5 %}
908908
{% tab 'Scala 3 only' for=enum_5 %}
909909

910910
```scala
@@ -926,7 +926,7 @@ enum Planet(mass: Double, radius: Double):
926926

927927
If you want to use Scala-defined enums as Java enums, you can do so by extending the class `java.lang.Enum` (which is imported by default) as follows:
928928

929-
{% tabs enum_6 class=tabs-scala-version %}
929+
{% tabs enum_6 %}
930930
{% tab 'Scala 3 only' for=enum_6 %}
931931

932932
```scala
@@ -953,7 +953,7 @@ The section on [algebraic datatypes][adts] and the [reference documentation][ref
953953
Case classes are used to model immutable data structures.
954954
Take the following example:
955955

956-
{% tabs case-classes_1 class=tabs-scala-version %}
956+
{% tabs case-classes_1 %}
957957
{% tab 'Scala 2 and 3' for=case-classes_1 %}
958958

959959
```scala:
@@ -966,7 +966,7 @@ case class Person(name: String, relation: String)
966966
Since we declare `Person` as a case class, the fields `name` and `relation` are public and immutable by default.
967967
We can create instances of case classes as follows:
968968

969-
{% tabs case-classes_2 class=tabs-scala-version %}
969+
{% tabs case-classes_2 %}
970970
{% tab 'Scala 2 and 3' for=case-classes_2 %}
971971

972972
```scala
@@ -978,7 +978,7 @@ val christina = Person("Christina", "niece")
978978

979979
Note that the fields can’t be mutated:
980980

981-
{% tabs case-classes_3 class=tabs-scala-version %}
981+
{% tabs case-classes_3 %}
982982
{% tab 'Scala 2 and 3' for=case-classes_3 %}
983983

984984
```scala
@@ -1092,7 +1092,7 @@ trait Person:
10921092

10931093
Then, create these case classes to extend that trait:
10941094

1095-
{% tabs case-classes_6 class=tabs-scala-version %}
1095+
{% tabs case-classes_6 %}
10961096
{% tab 'Scala 2 and 3' for=case-classes_6 %}
10971097

10981098
```scala
@@ -1134,7 +1134,7 @@ def getPrintableString(p: Person): String = p match
11341134
11351135
Notice these two patterns in the `case` statements:
11361136
1137-
{% tabs case-classes_8 class=tabs-scala-version %}
1137+
{% tabs case-classes_8 %}
11381138
{% tab 'Scala 2 and 3' for=case-classes_8 %}
11391139
11401140
```scala
@@ -1153,7 +1153,7 @@ Technically, the specific type of pattern case-classes_1ing shown in these examp
11531153
11541154
To show how that code works, create an instance of `Student` and `Teacher`:
11551155
1156-
{% tabs case-classes_9 class=tabs-scala-version %}
1156+
{% tabs case-classes_9 %}
11571157
{% tab 'Scala 2 and 3' for=case-classes_9 %}
11581158
11591159
```scala
@@ -1166,7 +1166,7 @@ val t = Teacher("Bob Donnan", "Mathematics")
11661166

11671167
Next, this is what the output looks like in the REPL when you call `getPrintableString` with those two instances:
11681168

1169-
{% tabs case-classes_10 class=tabs-scala-version %}
1169+
{% tabs case-classes_10 %}
11701170
{% tab 'Scala 2 and 3' for=case-classes_10 %}
11711171

11721172
```scala
@@ -1253,7 +1253,7 @@ They’re particularly useful whenever you need a singleton object that needs a
12531253
Case objects are useful when you need to pass immutable messages around.
12541254
For instance, if you’re working on a music player project, you’ll create a set of commands or messages like this:
12551255
1256-
{% tabs case-objects_1 class=tabs-scala-version %}
1256+
{% tabs case-objects_1 %}
12571257
{% tab 'Scala 2 and 3' for=case-objects_1 %}
12581258
12591259
```scala
@@ -1301,4 +1301,4 @@ def handleMessages(message: Message): Unit = message match
13011301
[fp-modeling]: {% link _overviews/scala3-book/domain-modeling-fp.md %}
13021302
[creator]: {{ site.scala3ref }}/other-new-features/creator-applications.html
13031303
[unapply]: {{ site.scala3ref }}/changed-features/pattern-matching.html
1304-
[trait-params]: {{ site.scala3ref }}/other-new-features/trait-parameters.html
1304+
[trait-params]: {{ site.scala3ref }}/other-new-features/trait-parameters.html

0 commit comments

Comments
 (0)