抽象和信息隐藏

发布于 2024-10-03 08:13:00 字数 77 浏览 4 评论 0原文

抽象意味着隐藏“实现细节”......那么抽象的目标就是实现信息隐藏?如果不是实现细节,信息隐藏中隐藏了什么? 信息隐藏技术的抽象程度如何?

Abstraction means hiding 'implementation details'..... So the goal of abstraction is to achieve information hiding?? And what is hidden in Information hiding if not implementation details??
And how abstraction is a technique to information hiding?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

人海汹涌 2024-10-10 08:13:00

抽象的目标不是隐藏变量值意义上的信息,即封装。

抽象的唯一目标是允许程序员在不理解算法或概念的情况下使用它。信息隐藏可能是其副产品,但这不是其目标。

The goal of abstraction is not to hide information in the sense of variable values, that would be encapsulation.

Abstraction's only goal is allow programmers to use an algorithm or concept without understanding it. Information hiding may be a by-product of this but it is not its goal.

痴者 2024-10-10 08:13:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

/* Example of Abstratcion: An application for mobile manufacturing company - Every phone must have to implement caller 
 * and sms feature but it depends on company to company (or model to model) if they want to include other features or not 
 * which are readily available , you just have to use it without knowing its implementation (like facebook in this example).
 */
namespace AbstractTest
{
    public abstract class feature
    {
        public abstract void Caller();
        public abstract void SMS();
        public void facebook()
        {
            Console.WriteLine("You are using facebook");
        }
    }    
    public class Iphone : feature    
    {
        public override void Caller()
        {
            Console.WriteLine("iPhone caller feature");
        }
        public override void SMS()
        {
            Console.WriteLine("iPhone sms feature");
        }
        public void otherFeature()
        {
            facebook();
        }
    }
    public class Nokia : feature
    {
        public override void Caller()
        {
            Console.WriteLine("Nokia caller feature");
        }
        public override void SMS()
        {
            Console.WriteLine("Nokia sms feature");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Iphone c1 = new Iphone();
            c1.Caller();
            c1.SMS();
            c1.otherFeature();
            Nokia n1 = new Nokia();
            n1.Caller();
            n1.SMS();
            Console.ReadLine();
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

/* Example of Abstratcion: An application for mobile manufacturing company - Every phone must have to implement caller 
 * and sms feature but it depends on company to company (or model to model) if they want to include other features or not 
 * which are readily available , you just have to use it without knowing its implementation (like facebook in this example).
 */
namespace AbstractTest
{
    public abstract class feature
    {
        public abstract void Caller();
        public abstract void SMS();
        public void facebook()
        {
            Console.WriteLine("You are using facebook");
        }
    }    
    public class Iphone : feature    
    {
        public override void Caller()
        {
            Console.WriteLine("iPhone caller feature");
        }
        public override void SMS()
        {
            Console.WriteLine("iPhone sms feature");
        }
        public void otherFeature()
        {
            facebook();
        }
    }
    public class Nokia : feature
    {
        public override void Caller()
        {
            Console.WriteLine("Nokia caller feature");
        }
        public override void SMS()
        {
            Console.WriteLine("Nokia sms feature");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Iphone c1 = new Iphone();
            c1.Caller();
            c1.SMS();
            c1.otherFeature();
            Nokia n1 = new Nokia();
            n1.Caller();
            n1.SMS();
            Console.ReadLine();
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文