O'Reilly Forums: Party Planner 2.0: Problem Understanding Cakewriting - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Party Planner 2.0: Problem Understanding Cakewriting

#1 User is offline   svHFCs 

  • New Member
  • Pip
  • Group: Members
  • Posts: 8
  • Joined: 09-August 14

  Posted 22 August 2014 - 08:12 PM

I'm really just not getting this encapsulation apparently because I have no idea what is the expected outcome with creating the CakeWriting property. I have two issues.

1) I've looked at the solution source code located at http://HeadFirstLabs...ooks//hfcsharp/ the Chapter 6 zip but the solution is wrong according to the book. It doesn't even use the "tooLongLabel" as expected. It's using a MessageBox. It's not even using the 'actualLength' field, which leads to question 2.

2) When was I supposed to create an int variable called actualLength? I don't see that indicated in the diagram? How is that supposed to work with the property ActualLenghth since it is already complete and using CakeWriting.Length?.

This is the solution online and it is wrong according to the description expected in the book. And this is from the book's official site. I don't see this doing anything described in the book. I thought it was supposed to employ methods in the book? It appears to me this is just duplicating code already written in the methods. So what is it I'm not understanding?

        public string CakeWriting
        {
            get { return this.cakeWriting; }
            set
            {
                int maxLength;
                if (CakeSize == 8)
                    maxLength = 16;
                else
                    maxLength = 40;
                if (value.Length > maxLength)
                {
                    MessageBox.Show("Too many letters for a " + CakeSize + " inch cake");
                    if (maxLength > this.cakeWriting.Length)
                        maxLength = this.cakeWriting.Length;
                    this.cakeWriting = cakeWriting.Substring(0, maxLength);
                }
                else
                    this.cakeWriting = value;
            }
        }

0

#2 User is offline   svHFCs 

  • New Member
  • Pip
  • Group: Members
  • Posts: 8
  • Joined: 09-August 14

Posted 24 August 2014 - 04:33 AM

Well, the solution is what I expected in the first place.It is just a basic property. Thanks to anyone who put up with my message of frustration while reviewing it.

private string CakeWriting() { get; set; }

This post has been edited by svHFCs: 24 August 2014 - 04:41 AM

0

#3 User is offline   AndrewStellman 

  • Andrew Stellman
  • PipPipPipPipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 787
  • Joined: 08-October 08
  • Gender:Male
  • Location:Brooklyn, NY
  • Interests:Author of: "Head First C#", "Beautiful Teams", "Head First PMP", "Applied Software Project Management"

Posted 24 August 2014 - 07:10 AM

Looks like you have a typo in the URL -- you added an extra slash, and somehow that brought you to a really ancient page from the old headfirstlabs.com website (which is why all the graphics are broken and it mentions a version of Visual Studio that's more than half a decade old).

Remove the extra slash from the URL so it matches what's in the book. That should redirect you to the book's store page on oreilly.com, with a link on the right-hand side of the page to the source code for the current edition.
Andrew Stellman
Author, Head First C#
Building Better Software -- http://www.stellman-greene.com
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users