Module 6: Introduction to App Development
Lesson 16: Designing the App's Architecture
Objective: Plan the architecture of the family photo-sharing app, including the user interface, data storage, and basic features.
Overview of the App Structure:
The family photo-sharing app will allow users to upload, store, and share photos with family members. The core components of the app include:
- User Interface: A simple, text-based interface where users can register, log in, create albums, and upload/view photos.
- Data Storage: Data such as user profiles, albums, and photos will be stored in linked lists and files.
- Basic Features: User registration, album creation, photo uploading, and viewing will be implemented first.
Designing the Data Structures:
Let’s revisit the key data structures we’ll use to represent users, albums, and photos:
type
PPhoto = ^TPhoto;
TPhoto = record
FileName: String;
DateUploaded: TDateTime;
Next: PPhoto;
end;
PAlbum = ^TAlbum;
TAlbum = record
Name: String;
Photos: PPhoto;
Next: PAlbum;
end;
PUser = ^TUser;
TUser = record
Name: String;
Password: String;
Albums: PAlbum;
Next: PUser;
end;
Explanation:
- TPhoto: represents a photo, including its file name, upload date, and a pointer to the next photo in the album.
- TAlbum: represents an album, including its name, a pointer to its photos, and a pointer to the next album.
- TUser: represents a user, including their name, password, a pointer to their albums, and a pointer to the next user.
Exercise - Implementing the Data Structures:
Implement the data structures above in Pascal. Ensure that the pointers are correctly set up to allow the dynamic linking of users, albums, and photos.
Lesson 17: Building the Core Functionality
Objective: Start building the core functionality of the app, including user registration, album creation, and photo uploading.
User Registration:
We’ll begin by allowing users to register. Here’s a simple function to register a new user:
function RegisterUser(var Head: PUser; Name, Password: String): PUser;
var
NewUser: PUser;
begin
New(NewUser);
NewUser^.Name := Name;
NewUser^.Password := Password;
NewUser^.Albums := nil;
NewUser^.Next := Head;
Head := NewUser;
RegisterUser := NewUser;
end;
Explanation:
- New(NewUser); allocates memory for the new user.
- NewUser^.Name := Name; assigns the user’s name.
- NewUser^.Password := Password; assigns the user’s password.
- NewUser^.Albums := nil; initializes the user’s albums to
nil
. - NewUser^.Next := Head; links the new user to the head of the user list.
- Head := NewUser; updates the head of the user list to the new user.
Album Creation:
Next, we’ll implement album creation for each user:
procedure CreateAlbum(var User: PUser; AlbumName: String);
var
NewAlbum: PAlbum;
begin
New(NewAlbum);
NewAlbum^.Name := AlbumName;
NewAlbum^.Photos := nil;
NewAlbum^.Next := User^.Albums;
User^.Albums := NewAlbum;
end;
Explanation:
- New(NewAlbum); allocates memory for the new album.
- NewAlbum^.Name := AlbumName; assigns the album’s name.
- NewAlbum^.Photos := nil; initializes the photo list to
nil
. - NewAlbum^.Next := User^.Albums; links the new album to the user’s existing albums.
- User^.Albums := NewAlbum; updates the user’s album list to include the new album.
Photo Uploading:
We’ll also need functionality for users to upload photos to their albums:
procedure UploadPhoto(var Album: PAlbum; FileName: String; DateUploaded: TDateTime);
var
NewPhoto: PPhoto;
begin
New(NewPhoto);
NewPhoto^.FileName := FileName;
NewPhoto^.DateUploaded := DateUploaded;
NewPhoto^.Next := Album^.Photos;
Album^.Photos := NewPhoto;
end;
Explanation:
- New(NewPhoto); allocates memory for the new photo.
- NewPhoto^.FileName := FileName; assigns the file name of the photo.
- NewPhoto^.DateUploaded := DateUploaded; records the upload date of the photo.
- NewPhoto^.Next := Album^.Photos; links the new photo to the beginning of the album’s photo list.
- Album^.Photos := NewPhoto; updates the album’s photo list to include the new photo.
Exercises:
- Implement the user registration, album creation, and photo uploading features as described above. Test each feature to ensure it works correctly.
- Create a simple menu system that allows users to choose between registering, creating albums, and uploading photos. Use a loop to keep the menu running until the user decides to exit.
Viewing Photos:
Finally, users should be able to view the photos they’ve uploaded. Here’s a simple procedure to list all photos in an album:
procedure ViewPhotos(Album: PAlbum);
var
Temp: PPhoto;
begin
Temp := Album^.Photos;
while Temp <> nil do
begin
writeln('Photo: ', Temp^.FileName, ' Uploaded on: ', DateTimeToStr(Temp^.DateUploaded));
Temp := Temp^.Next;
end;
end;
Explanation:
- Temp := Album^.Photos; starts at the first photo in the album.
- while Temp <> nil do: loops through the photo list until the end is reached.
- writeln(...); prints the file name and upload date of each photo.
- Temp := Temp^.Next; moves to the next photo in the list.
Exercise - Implementing Photo Viewing:
Implement the photo viewing feature and test it by creating an album, uploading photos, and then listing them.
Next Steps:
In the next module, we’ll expand the app with more advanced features, such as user authentication, sharing photos with specific users, and managing privacy settings.