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

  • Home
  • SEARCH
  • 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 877739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:39:35+00:00 2026-05-15T11:39:35+00:00

I’ve always been taught that if you are doing something to an object, that

  • 0

I’ve always been taught that if you are doing something to an object, that should be an external thing, so one would Save(Class) rather than having the object save itself: Class.Save().

I’ve noticed that in the .Net libraries, it is common to have a class modify itself as with String.Format() or sort itself as with List.Sort().

My question is, in strict OOP is it appropriate to have a class which performs functions on itself when called to do so, or should such functions be external and called on an object of the class’ type?

  • 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-05-15T11:39:35+00:00Added an answer on May 15, 2026 at 11:39 am

    Great question. I have just recently reflected on a very similar issue and was eventually going to ask much the same thing here on SO.

    In OOP textbooks, you sometimes see examples such as Dog.Bark(), or Person.SayHello(). I have come to the conclusion that those are bad examples. When you call those methods, you make a dog bark, or a person say hello. However, in the real world, you couldn’t do this; a dog decides himself when it’s going to bark. A person decides itself when it will say hello to someone. Therefore, these methods would more appropriately be modelled as events (where supported by the programming language).

    You would e.g. have a function Attack(Dog), PlayWith(Dog), or Greet(Person) which would trigger the appropriate events.

    Attack(dog)      // triggers the Dog.Bark event 
    Greet(johnDoe)   // triggers the Person.SaysHello event 
    

    As soon as you have more than one parameter, it won’t be so easy deciding how to best write the code. Let’s say I want to store a new item, say an integer, into a collection. There’s many ways to formulate this; for example:

    StoreInto(1, collection)    // the "classic" procedural approach
    1.StoreInto(collection)     // possible in .NET with extension methods
    Store(1).Into(collection)   // possible by using state-keeping temporary objects
    

    According to the thinking laid out above, the last variant would be the preferred one, because it doesn’t force an object (the 1) to do something to itself. However, if you follow that programming style, it will soon become clear that this fluent interface-like code is quite verbose, and while it’s easy to read, it can be tiring to write or even hard to remember the exact syntax.


    P.S.: Concerning global functions: In the case of .NET (which you mentioned in your question), you don’t have much choice, since the .NET languages do not provide for global functions. I think these would be technically possible with the CLI, but the languages disallow that feature. F# has global functions, but they can only be used from C# or VB.NET when they are packed into a module. I believe Java also doesn’t have global functions.

    I have come across scenarios where this lack is a pity (e.g. with fluent interface implementations). But generally, we’re probably better off without global functions, as some developers might always fall back into old habits, and leave a procedural codebase for an OOP developer to maintain. Yikes.

    Btw., in VB.NET, however, you can mimick global functions by using modules. Example:

    Globals.vb:

        Module Globals
            Public Sub Save(ByVal obj As SomeClass)
                ...
            End Sub
        End Module
    

    Demo.vb:

        Imports Globals
        ...
        Dim obj As SomeClass = ...
        Save(obj)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.