Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9125849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:53:58+00:00 2026-06-17T06:53:58+00:00

In languages like Java and C++ we give parameters to constructors. How do you

  • 0

In languages like Java and C++ we give parameters to constructors.

How do you do this in Pharo Smalltalk?

I want something like

|aColor|
aColor = Color new 'red'.

Or is this bad practice and should I always do

|aColor|
aColor = Color new.
aColor name:= red.d
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:54:00+00:00Added an answer on June 17, 2026 at 6:54 am

    The short answer is that you can do pretty much the same in Smalltalk. From the calling code it would look like:

    aColor := Color named: 'Red'.
    

    The long answer is that in Smalltalk you don’t have constructors, at least not in the sense that you have a special message named after the class. What you do in Smalltalk is defining class-side messages (i.e. messages understood by the class, not the instance[*]) where you can instantiate and configure your instances. Assuming that your Color class has a name instance variable and a setter for it, the #named: method would be implemented like:

    (class) Color>>named: aName
    | color |
    color := self new.
    color name: aName.
    ^color.
    

    Some things to note:

    • We are using the #new message sent to the class to create a new instance. You can think of the #new message as the primitive way for creating objects (hint: you can browse the implementors of the #new message to see how it is implemented).
    • We can define as many class methods as we want to create new ‘configured’ instances (e.g. Color fromHexa:) or return pre-created ones (e.g. Color blue).
    • You can still create an uninitialized instance by doing Color new. If you want to forbid that behavior then you must override the #new class message.

    There are many good books that you can read about Smalltalk basics at Stef’s Free Online Smalltalk Books

    [*] This is quite natural due to the orthogonal nature on Smalltalk, since everything (including classes) is an object. If you are interested check Chapter 13 of Pharo by Example or any other reference to classes and metaclasses in Smalltalk.

    HTH

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am very new to symfony. In other languages like java and others I
In languages like Java, overloading can be used in this way: void test($foo, $bar){}
I moved one years ago from classic OO languages such like Java to JavaScript.
With generics on languages like C# or Java, you can have a factory that
When I read about the performance of JITted languages like C# or Java, authors
Possible Duplicate: Should C++ eliminate header files? In languages like C# and Java there
I've seen a few neat features in other languages around Java like generators and
Is the nesting of functions possible in the object oriented languages like C#, Java,
JSON stands for JavaScript Object Notation. But how come languages like php, java, c
I'm writing a new Java 6 Swing application and want to have a Show

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.