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 8339403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:52:37+00:00 2026-06-09T04:52:37+00:00

I have a Rectangle class which has properties width and height. It also has

  • 0

I have a Rectangle class which has properties width and height. It also has an instance property/object called origin (-(XYPoint *) origin ). Below is the code for my designated initializer in which I pass the XYPoint object as an argument. Is there a way (or is it okay) if I take the properties of the XYPoint class as arguments in this method and then initialize the XYPoint object as well as allocate memory for it inside the method? Otherwise I have to create an XYPoint object in my main program and pass it as an argument which is a lot more code to type.

-(id) initWithWidth:(int)w andHeight:(int)h andOrigin:(XYPoint *)o
{
    self = [super init];
    if (self) {
        [self setWidth: w andHeight: h];
        self.origin = o;
    }
    return self;
}

P.S.- I am new to programming and Objective C so pardon me if I have stated something technically wrong in my question. Thanks!

  • 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-09T04:52:38+00:00Added an answer on June 9, 2026 at 4:52 am

    Personally–I try to avoid initializers that take parameters. I think it leads to writing lots more code and inflexibility. I use designated initializers for just 2 things:

    • initializing an object with properties that must not be changed after the object is initialized
    • initializing an object with properties that are absolutely needed to construct it and cannot be specified later

    In general, for Rectangle class, I’d make the use like this:

    Rectangle * r = [ [ Rectangle alloc ] init ] ;
    r.x = x ;
    r.y = y ;
    r.origin = o ;
    
    // use r
    

    and not use the designated initializer pattern at all except for the conditions outlined above. (For example, creating immutable Rectangle instances)

    Finally, there’s probably no need to create a Rectangle class–just use CGRect/NSRect primitive structures.

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

Sidebar

Related Questions

I have a rectangle which has known width and height.Now devide rectangle diagonally to
Let's say we have a template class Area , which has a member variable
The code below shows a rectangle class using double points, which are also stored
I have a JFrame . I also have a Box class which extends Component
Here is the code I have written for Rectangle class. class Rectangle (l: Double,
I have this code: public class Area { Texture2D point; Rectangle rect; SpriteBatch _sB;
I have one rectangle. The width of the rectangle is deciding based on the
I have a rectangle that I've created and set its individual properties like so
I have a problem with a class which extends ListBox in Windows Phone 7
I have 2 Xaml files, one containing a DataTemplate which has a resource definition

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.